Arrays PowerShell中数组的字符串(不带分隔符)

Arrays PowerShell中数组的字符串(不带分隔符),arrays,string,powershell,formatting,Arrays,String,Powershell,Formatting,我正在尝试使用WMI获取计算机登录会话的开始时间,方法是: $starttimes=获取WmiObject Win32\u登录会话-计算机名HM-ITS-KLP| 选择开始时间 这给我的日期格式如下: 20170120075444.819609+000 (yyyymmddhhmmss.??????+???) 您忘记扩展“starttime”属性。尝试更改以下内容: foreach ( $line in $starttimes){ $dateArray = $line.starttime.toC

我正在尝试使用WMI获取计算机登录会话的开始时间,方法是:

$starttimes=获取WmiObject Win32\u登录会话-计算机名HM-ITS-KLP|
选择开始时间
这给我的日期格式如下:

20170120075444.819609+000 (yyyymmddhhmmss.??????+???) 您忘记扩展“starttime”属性。尝试更改以下内容:

foreach ( $line in $starttimes){
$dateArray = $line.starttime.toCharArray()
或者这个:

foreach ( $line in $starttimes.starttime){
$dateArray = $line.toCharArray()
$starttimes = Get-WMIObject Win32_LogonSession |  select -Expand starttime
foreach ( $line in $starttimes){
或者这个:

foreach ( $line in $starttimes.starttime){
$dateArray = $line.toCharArray()
$starttimes = Get-WMIObject Win32_LogonSession |  select -Expand starttime
foreach ( $line in $starttimes){
您忘记扩展“starttime”属性。尝试更改以下内容:

foreach ( $line in $starttimes){
$dateArray = $line.starttime.toCharArray()
或者这个:

foreach ( $line in $starttimes.starttime){
$dateArray = $line.toCharArray()
$starttimes = Get-WMIObject Win32_LogonSession |  select -Expand starttime
foreach ( $line in $starttimes){
或者这个:

foreach ( $line in $starttimes.starttime){
$dateArray = $line.toCharArray()
$starttimes = Get-WMIObject Win32_LogonSession |  select -Expand starttime
foreach ( $line in $starttimes){
试试这个:

Get-WmiObject Win32_LogonSession -ComputerName "HM-ITS-KLP" | select  @{N='starttime';E={$_.ConvertToDateTime($_.starttime)}}
试试这个:

Get-WmiObject Win32_LogonSession -ComputerName "HM-ITS-KLP" | select  @{N='starttime';E={$_.ConvertToDateTime($_.starttime)}}

非常感谢,马上解决了我的问题!非常感谢,马上解决了我的问题!我强烈建议不要乱搞字符数组。我强烈建议不要乱搞字符数组。