我想将我的 IIS Bidings 输出到 csv 或 txt ,我只是在使用该 cmdlet 玩了一下:
Get-ChildItem -path IIS:\Sites
效果很好,使用此命令也可以完美地输出到 .txt :
Get-ChildItem -path IIS:\Sites | out-file "D:\_utils\PowerShell Scripts\IISexport\IISExport.txt"
但是,一旦我将它包装到一个函数中,powershell 就会尝试找到当然不存在的物理路径 IIS:\Sites。
Get-ChildItem : Cannot find drive. A drive with the name 'IIS' does not exist.
At D:\_utils\PowerShell Scripts\IISReport.ps1:8 char:1
到目前为止,我的脚本非常简单:
$today = Get-Date -format M.d.yyyy
function IISexport
{
Get-ChildItem -path IIS:\Sites
}
IISexport | out-file "D:\_utils\PowerShell Scripts\IISexport\IISExport$today.txt"
我错过了什么?我想把它排除在外,因为我想把它放到一个更大的脚本中,从 xx 网络服务器中排除我的网络绑定。
我认为这与控制台中已经给出但不在我的脚本中的环境变量有关。但我不知道如何管理它们。已经尝试过get-childitem evn:
,这给我带来了很多变数。