I have several web servers where I use Powershell to perform inventory tasks.
Recently, two of my servers started giving me this error when they try to execute get-website in a Powershell script that is run as a scheduled task:
get-website : Could not load file or assembly'Microsoft.PowerShell.Commands.Utility' or one of its dependencies. The system
cannot find the file specified.
At E:\scripts\DetailedInv.ps1:61 char:21
+ ForEach($website in get-website){
+ ~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Website], FileNotFoundExc
eption
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.IIs.Po
werShell.Provider.GetWebsiteCommand
These are windows 2008 R2 X64 servers that are fully patched.
The strange thing is, I use this same script on all my web servers, but these two generate this error. If I open the script in the Powershell ISE and execute it on the problem server, the script runs successfully, but if I right click on the script and choose "Run with PowerShell" the above error appears and no information in generated.
Any idea what could be causing this?