The Powershell team works in Powershell, but not inside the script, why?

I needed to disable my IIS bets in csv or txt, I just play around a bit with this cmdlet:

Get-ChildItem -path IIS:\Sites

which works fine, as well as overflowing the .txt file works fine with this command:

Get-ChildItem -path IIS:\Sites | out-file "D:\_utils\PowerShell Scripts\IISexport\IISExport.txt"

But as soon as I complete it in the powershell function, it will try 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 actually simple:

$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 like to put it in a larger script that reconfigures my webbindings from xx webservers.

I think this is due to env variables that are already specified in the console, but not inside my script. But I do not know how to manage it. Already tried get-childitem evn: which returned me a lot of variables.

+4
1

script, IIS:

Import-Module WebAdministration;

, @KyleMit:, WebAdministration, ( )

Import-Module ServerManager; Add-WindowsFeature Web-Scripting-Tools
+14

Source: https://habr.com/ru/post/1545665/


All Articles