2016-06-08 181 views
0

任何人都可以帮助我如何获得一个Get-Date或当前日期当放在列"WhenCreated"后?如何在Get-ADComputer中获取当前日期?

Get-ADComputer <servername> -Properties * -Server "domain.com" | Select ObjectGUID,Name,CanonicalName,PasswordLastSet,WhenCreated | Export-CSV "E:\Data\Scripts\Computer2.csv" 

我的期望会出现如下结果。

ObjectGUID,Name,CanonicalName,PasswordLastSet,WhenCreated,CurrentDate 

我试图把这样的:

$Date = Get-Date 
Get-ADComputer <servername> -Properties * -Server "domain.com" | 
    Select ObjectGUID,Name,CanonicalName,PasswordLastSet,WhenCreated,$Date | 
    Export-Csv "E:\Data\Scripts\Computer2.csv" 

仍然得到了一个错误。

+1

的可能的复制[选择AD成员属性+额外的列(http://stackoverflow.com/questions/10127410/select-ad -member-properties-extra-column) –

回答

-1

您将不得不使用Get-WmiObject方法而不是Get-Date,因为PowerShell会将收到的信息转换为本地主机的时间。

为此,您必须将远程wmi对象存储在变量(目标计算机)中,以便实际使用它,然后从您设置的WMI对象获取LocalDateTime属性并将其转换为(- $Win32OSVar.ConvertToDateTime($Win32OSVar.LocalDateTime)),然后使时间差异(如果您需要 - 只需减去2个变量)。

的WmiObject可以用于该目的是.CurrentTimeZone

例:(Get-WmiObject -Class Win32_OperatingSystem).CurrentTimeZone

+0

这并没有解决这个问题。 –

+0

怎么样? Get-Date不起作用,而必须使用Get-WmiObject。什么不清楚? – Overmind

+0

我不明白为什么'Get-Date'会奇迹般地产生当前日期。 –