每次我运行下面的脚本
不能将参数“FilePath”绑定到参数‘’,因为它是null。
昨晚起作用了。没有作出任何改变,今天上午就失败了。有趣的是,如果我保存脚本,然后运行它,它就能工作。但是,如果我清除控制台,然后再次运行它,它将失败。
我漏掉了什么明显的东西吗?
New-Item -ItemType Directory -Force -Path C:\NonStandard_Services
set-location C:\NonStandard_Services
$Computers= Get-Content C:\computers.txt
$Report= $file
$file= $Computer
ForEach ($Computer in $Computers)
{
Get-WmiObject -ComputerName $Computer -class Win32_Service -ErrorAction SilentlyContinue |
Where-Object -FilterScript {$_.StartName -ne "LocalSystem"}|
Where-Object -FilterScript {$_.StartName -ne "NT AUTHORITY\NetworkService"} |
Where-Object -FilterScript {$_.StartName -ne "NT AUTHORITY\LocalService"} |
Select-Object -Property StartName,Name,DisplayName|
ConvertTo-Html -Property StartName,Name,DisplayName -head $HTML -body "<H2>Non- Standard Service Accounts on $Computer</H2>"| Out-File $Report -Append}
#Rename-Item c:\GP_Services\Report.htm $file
Get-ChildItem | Where-Object {$_.extension -ne ".htm"} | Rename-Item -newname { $_.name + '.htm' }发布于 2015-06-05 10:54:10
$Report= $file $file= $Computer ForEach ($Computer in $Computers) {.}
在其他变量本身被分配值之前,可以将它们赋值给它们。将上面的内容改为:
ForEach ($Computer in $Computers) {
$file = $Computer
$Report = $file
...
}或直接在$Computer中使用Out-File
... | Out-File "$Computer.txt" -Appendhttps://stackoverflow.com/questions/30664291
复制相似问题