Link to home
Start Free TrialLog in
Avatar of c7c4c7
c7c4c7Flag for United States of America

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.PowerShell.Commands.GetContentCommand

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
Avatar of jmcg
jmcg
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of c7c4c7

ASKER

It's a mapped drive
What does Setting the login for the scheduled task mean
Avatar of c7c4c7

ASKER

Never even paid any attention to that field, thanks for the suggestion