转换LastLogon到DateTime格式 [英] Converting LastLogon to DateTime format

查看:1709
本文介绍了转换LastLogon到DateTime格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是让用户列表从我有以下信息域:

- 显示名称 -国家 -Manager名称 - 最后登陆日期

我运行下面的脚本,一切都看起来不错,除了LastLogon。它输出的时候到了一堆随机数,如129948127853609000的。我怎样才能将其转换为DateTime格式?

 搜索-ADAccount -UsersOnly -SearchBaseOU =国际,DC = myCompany中,DC = COM-AccountDisabled:$假|获取-ADUser便有-Properties名称,经理,LastLogon |选择名称,经理,LastLogon |出口CSV C:\ Australia.csv -NoTypeInformation
 

解决方案

DateTime.FromFileTime 应该做的伎俩:

  PS C:\> [日期时间] :: FromFileTime(129948127853609000)

周一,2012年10月15日下午3时13分05秒
 

然后根据你想如何格式化,请标准和的自定义日期时间格式的字符串。

  PS C:\> [日期时间] :: FromFileTime(129948127853609000)的ToString(倒是MMMM')
10月15日
PS C:\> [日期时间] :: FromFileTime(129948127853609000)的ToString('G')
2012年10月15日下午3时13分
 

如果您希望将这一到您的一行程序,改变你的选择语句如下:

  ... |选择名称,经理,@ {N ='LastLogon'; E = {[日期时间] :: FromFileTime($ _ LastLogon。)}} | ...
 

My objective is to get a list of users from my domain with the following info:

-Display name -Country -Manager Name -Last login date

I am running the following script, and everything looks good except for the LastLogon. It outputs the time into a bunch of random numbers like "129948127853609000". How can I convert this to DateTime format?

Search-ADAccount -UsersOnly -SearchBase "OU=International,DC=mycompany,DC=com" -AccountDisabled:$false | Get-ADUser -Properties Name, manager, LastLogon | Select Name, manager, LastLogon | export-csv C:\Australia.csv -NoTypeInformation

解决方案

DateTime.FromFileTime should do the trick:

PS C:\> [datetime]::FromFileTime(129948127853609000)

Monday, October 15, 2012 3:13:05 PM

Then depending on how you want to format it, check out standard and custom datetime format strings.

PS C:\> [datetime]::FromFileTime(129948127853609000).ToString('d MMMM')
15 October
PS C:\> [datetime]::FromFileTime(129948127853609000).ToString('g')
10/15/2012 3:13 PM

If you want to integrate this into your one-liner, change your select statement to this:

... | Select Name, manager, @{N='LastLogon'; E={[DateTime]::FromFileTime($_.LastLogon)}} | ...

这篇关于转换LastLogon到DateTime格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆