因此,我一直在尝试学习一些Powershell,并在尝试制作以下脚本(从Get-Process获取所有Starttime值并将其保存为DateTime对象的Time部分之外的形式。)
$a=( Get-Process |Where-Object ProcessName -NotMatch 'Idle' | Select-Object -property starttime);
#I think Select-Object part may not be necessary, but left in as that's how
#I've coded it
$b= $a.starttime;
$c=New-Object System.Collections.Generic.List[DateTime];
$count=0; @(0..($b.length-1)).foreach({ Write-Host $count,$b[$_].ToShortDateString(); $c.add($b[$_].ToShortDateString()); $count++ })
并且我认为它按照我的意图进行。调用$b[j]-$c[j]
仅产生分钟,秒,毫秒的值。但是,当我调用长度时,得到以下内容
$b.length
175
$c.length
1
1
1
等,
那为什么呢?我不太了解powershell(玩了大约一周),并且觉得$c.length
应该吐出与$b.length
相同的值吗?我做错了什么?
首先,解决此问题的方法很简单-使用Count
获取列表中项目的总数: