Reputation: 8830
I'm calling Restart-WebAppPool with the name of a web application pool that verifiably exists. When I execute that command in the context of a script it errors with Cannot find path 'IIS:\AppPools\AppPoolName' because it does not exist.
. When I execute the exact same command in powershell console it runs like a charm.
I load the WebAdministration module at the beginning of the script using Import-Module WebAdministration
. I rely on other commands from that module in a number of spots in the script, all of which operate successfully. I am logging the name of the app pool I am trying to restart into a log file right before calling the command, and the name there is right as well as being correct in error message. I am retrieving the app pool name with (Get-ItemProperty -Path $SitePath).ApplicationPool
where $SitePath has been used throughout the script to operate on the site in question.
Extra-annoyingly, immediately before trying to restart the app pool I reset the root directory of the application in question to a new physical path using (Set-ItemProperty -Path $SitePath -Name "PhysicalPath" -Value $fullAppPath )
, which works perfectly, so I know WebAdministration is loaded (the most obvious reason for not being able to find the path of the app pool that I'm aware of).
The app pool name that I'm trying to restart (aside from restarting in a powershell command prompt) shows up in Get-ChildItem -Path "IIS:\AppPools"
What else am I missing that would cause WebAdministration not to be able to find that app pool?
Upvotes: 0
Views: 1267