你忘了扩展"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){