c7c4c7
asked on
Powershell script will not run as a Scheduled Task
I have a script that is called from a VBS script that will not run if executed as a scheduled task
When I run it from the scheduled task I get the following error
Get-Content : Cannot find drive. A drive with the name 'l' does not exist.
At C:\powershell\sendlog.ps1: 11 char:9
+ $Body = Get-Content $BodyPath | Out-String
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (l:String) [Get-Content], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.Po werShell.C ommands.Ge tContentCo mmand
The code that it is executing is
$BodyPath = "l:\logs\events.html"
$Body = Get-Content $BodyPath | Out-String
$attArray=@(Get-ChildItem "l:\logs\*.png" | Where {-NOT $_.PSIsContainer}) | foreach {$_.fullname}
The drive does exist and can be accessed, no problem.
If I execute the same VBS script from a CMD prompt or from within a Powershell Command Line Window I get no errors and everything runs fine
Does anyone have any suggestions
Thanks for the help
When I run it from the scheduled task I get the following error
Get-Content : Cannot find drive. A drive with the name 'l' does not exist.
At C:\powershell\sendlog.ps1:
+ $Body = Get-Content $BodyPath | Out-String
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (l:String) [Get-Content], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.Po
The code that it is executing is
$BodyPath = "l:\logs\events.html"
$Body = Get-Content $BodyPath | Out-String
$attArray=@(Get-ChildItem "l:\logs\*.png" | Where {-NOT $_.PSIsContainer}) | foreach {$_.fullname}
The drive does exist and can be accessed, no problem.
If I execute the same VBS script from a CMD prompt or from within a Powershell Command Line Window I get no errors and everything runs fine
Does anyone have any suggestions
Thanks for the help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Never even paid any attention to that field, thanks for the suggestion
ASKER
What does Setting the login for the scheduled task mean