I wanted to outfile my IIS Bidings to csv or txt , I am simply playing around a bit using that cmdlet :
Get-ChildItem -path IIS:\Sites
which works perfectly, also outfiling to .txt works perfect using this command :
Get-ChildItem -path IIS:\Sites | out-file "D:\_utils\PowerShell Scripts\IISexport\IISExport.txt"
But as soon as I wrap it into a function powershell tries to find the physical path IIS:\Sites which of course does not exist.
Get-ChildItem : Cannot find drive. A drive with the name 'IIS' does not exist.
At D:\_utils\PowerShell Scripts\IISReport.ps1:8 char:1
my script is really simple so far :
$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"
What am I missing ? I would like to outfile this because I would love to put it into a bigger script which outfiles my webbindings from xx webservers.
I think it's related to the env variables which are given already in the console but not inside my script. But I don't know how to manage them. Already tried get-childitem evn:
which returned me a lot of variables.