[英]SCCM LastLogonTimestamp format queried by PowerShell
I would like to know how it is possible to convert the LastLogonTimestamp found in the SCCM database to a readable format. 我想知道如何将SCCM数据库中找到的LastLogonTimestamp转换为可读格式。 The code I have now is the following: 我现在的代码如下:
$SCCMServer = 'SERVERSCCM'
$SCCMModule = 'C:\Program Files (x86)\Microsoft Configuration Manager\bin\ConfigurationManager.psd1'
$SamAccountName = 'test'
Function Get-SCCMSite {
Param (
[Parameter(Mandatory=$true)]
[String]$ComputerName
)
Process {
Get-WmiObject -ComputerName $ComputerName -Namespace 'root\SMS' -Class 'SMS_ProviderLocation' |
ForEach-Object{
if ($_.ProviderForLocalSite -eq $true) {$SiteCode=$_.sitecode}
}
if ($SiteCode -eq '') {
throw ('Sitecode of ConfigMgr Site at ' + $ComputerName + ' could not be determined.')
}
else {
Return $SiteCode
}
}
}
Import-Module $SCCMModule
$SCCMSite = Get-SCCMSite -ComputerName $SCCMServer
Set-Location "$SCCMSite`:"
$SCCMNameSpace="root\SMS\site_$SCCMSite"
Get-WmiObject -namespace $SCCMNameSpace -computer $SCCMServer -query "select * from sms_r_system where LastLogonUserName='$SamAccountName'" | select *
The output of LastLogonTimestamp
looks like this: LastLogonTimestamp
的输出如下所示:
LastLogonTimestamp : 20150330132039.000000+***
On the web I found that this format could be converted to a readable format like this: 在网络上,我发现这种格式可以转换为可读格式,如下所示:
[datetime]::FromFileTime(20150330132039.000000+***).ToString('d MMMM yyyy')
But it's not really working as it outputs errors. 但它并没有真正起作用,因为它输出错误。 When I remove the last part behind the .
当我删除后面的最后一部分.
it gives me a date in 1601, which is definitely incorrect. 它给我一个1601年的日期,这绝对不正确。
I don't think the FromFileTime
method is the correct one for this situation. 我不认为FromFileTime
方法对于这种情况是正确的。
You can use the ParseExact
method with a bit of manipulation of the original value: 您可以使用ParseExact
方法对原始值进行一些操作:
> $lastlogonstamp = "20150330132039.000000+***"
> $dt = [datetime]::parseexact($lastlogonstamp.split('.')[0],"yyyyMMddHHmmss",[System.Globalization.CultureInfo]::InvariantCulture)
> $dt
30 March 2015 13:20:39
> $dt.ToString('d MMMM yyyy')
30 March 2015
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.