我正在尝试获取上次启动时间报告,并且我的脚本不再重复相同的输出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
答案 0 :(得分: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
答案 1 :(得分:0)
所以你的问题是当你进行for循环时,你使用了错误的变量。请记住,当您使用for循环时,必须使用$Server
而不是$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