I'm working on a script to rotate my IIS logs. The scipt I've written works fine in the shell but when I run it as a scheduled task it fails.
I've cut the script down to only these lines:
Start-Transcript "D:\scheduled_task.log"
Import-Module WebAdministration
$LogfileDirectory = (Get-ItemProperty "IIS:\Sites\Default Web Site").logfile.directory
$LogfileDirectory
Stop-Transcript
And the output of Start-Transcript is:
**********************
Windows PowerShell transcript start
Start time: 20130130192555
Username : HOSTED\jimho
Machine : WEB01 (Microsoft Windows NT 6.1.7601 Service Pack 1)
**********************
Transcript started, output file is D:\scheduled_task.log
Get-ItemProperty : Could not load file or assembly
'Microsoft.PowerShell.Commands.Management' or one of its dependencies. The
system cannot find the file specified.
At D:\Mediclick\eMaterials\Tools\LogArchiverTEST.ps1:5 char:22
+ $LogfileDirectory = (Get-ItemProperty "IIS:\Sites\Default Web
Site").logfile.dir ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ItemProperty], FileNotFou
ndException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerS
hell.Commands.GetItemPropertyCommand
**********************
Windows PowerShell transcript end
End time: 20130130192556
**********************
I've set/un-set every option on the General tab of the task properties, I've entered the full path to the powershell exe and the full path to my script is entered in the Add Arguments box. I've tried appending a couple things (-noprofile, etc.) but still no joy. This is on Server 2008 R2.
Any ideas?