首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能将参数"FilePath“绑定到参数”FilePath“,因为它为空

不能将参数"FilePath“绑定到参数”FilePath“,因为它为空
EN

Stack Overflow用户
提问于 2015-06-05 10:29:32
回答 1查看 15.3K关注 0票数 2

每次我运行下面的脚本

不能将参数“FilePath”绑定到参数‘’,因为它是null。

昨晚起作用了。没有作出任何改变,今天上午就失败了。有趣的是,如果我保存脚本,然后运行它,它就能工作。但是,如果我清除控制台,然后再次运行它,它将失败。

我漏掉了什么明显的东西吗?

代码语言:javascript
复制
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' }
EN

回答 1

Stack Overflow用户

发布于 2015-06-05 10:54:10

$Report= $file $file= $Computer ForEach ($Computer in $Computers) {.}

在其他变量本身被分配值之前,可以将它们赋值给它们。将上面的内容改为:

代码语言:javascript
复制
ForEach ($Computer in $Computers) {
  $file   = $Computer
  $Report = $file
  ...
}

或直接在$Computer中使用Out-File

代码语言:javascript
复制
... | Out-File "$Computer.txt" -Append
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30664291

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档