0

我正在尝试获取上次启动时间报告,并且我的脚本一直重复相同的输出 8 次,我确定它是语法错误。这是我所拥有的:

$ServerName = (Get-Content -Path 
D:\Users\Admin.sa\Desktop\Computerlist.txt)

##### Script Starts Here ######  

foreach ($Server in $ServerName) {Get-CimInstance -Cn $Servername -ClassName 
win32_operatingsystem | select csname,lastbootuptime}

Format-Table -AutoSize
4

2 回答 2

1

我相信问题出在你的for循环中。尝试:

$ServerName = (Get-Content -Path "D:\Users\Admin.sa\Desktop\Computerlist.txt")

##### Script Starts Here ######  

foreach ($Server in $ServerName) {Get-CimInstance -Cn $Server -ClassName win32_operatingsystem | select csname,lastbootuptime}

Format-Table -AutoSize
于 2017-09-07T14:53:55.810 回答
0

所以你的问题是,当你执行 for 循环时,你使用了错误的变量。请记住,当您使用 for 循环时,您必须使用$ServerNOT$ServerName

所以:

$ServerName = (Get-Content -Path 
D:\Users\Admin.sa\Desktop\Computerlist.txt)

##### Script Starts Here ######  

foreach ($Server in $ServerName) {Get-CimInstance -Cn $Server -ClassName 
win32_operatingsystem | select csname,lastbootuptime}

Format-Table -AutoSize
于 2017-09-07T15:33:10.477 回答