我想将我的IIS绑定导出为CSV或TXT文件,我只是试着使用以下命令:
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个Web服务器中输出我的Web绑定。
我认为这与环境变量有关,这些变量已经在控制台中给出,但不在我的脚本中。但是我不知道如何管理它们。已经尝试过get-childitem evn:
,它返回了很多变量。