0

I have a powershell script on my network share (\server\dir\my.ps1).

  • if I run this from command prompt (powershell -file "\server\dir\my.ps1") than work as expected.

  • if I create a basic task in the scheduler with "Run Only When user logged on" than works as expected.

  • if check the "Run Whether user is logged on or not" then script won't run

  • in the action tab:Progam/Script --> powershell; Arguments:-file "\server\dir\my.ps1"

  • in the task history I see the task run well ...but the script does nothing...
  • the user is a regular user

  • If I change the user to administrator than everything work as expected....

Is it possible to run scheduled task with regular user with "run whether user is logged on or not"?

#

So i made some test:

In the PS file i put this script:

Test-Connection -ComputerName SBS | out-file "c:\script\test.txt" $olSession = (New-Object -ComObject Outlook.Application).Session $olSession.Logon('Outlook') $contactsFolder = 10 $elemek = $olSession.GetDefaultFolder($contactsFolder).Items @($elemek)|ForEach-Object {$_.Delete()}

  • The first line run as expected (with user logged on or not )
  • The rest of line did not run
  • If i paste this lines to cmd than everything run as expected
  • If i change the settings to "Run only if user logged in" than every line run as expected
  • If i give admin rights to user the everything run as expected in logged off too...

So something with my outlook session lines...i don't understand...

6
  • Does the user have "Log on as batch job" rights?
    – DarkMoon
    Feb 24, 2015 at 10:09
  • Yes. In domain policy i granted right for the user. (before i made this settings, i can't save the task9
    – holian
    Feb 24, 2015 at 14:09
  • Try specifying the full path to the executable "c:\windows\system32\windowspowershel\1.0\powershell.exe", rather than just "powershell". You may not get a full environment when running a task while logged off, in which case the PATH variable won't be able to help find powershell.
    – DarkMoon
    Feb 24, 2015 at 19:39
  • nope...i edited my post with a short test...please if you could take a look at....thx
    – holian
    Feb 25, 2015 at 6:51
  • Oh, I have a feeling that because there is no desktop to launch on, the session doesn't get created. Try something like if ($olSession) { <do the script as normal> } else { "Variable not initialized" | Out-File "c:\script\VarNotInit.txt" }
    – DarkMoon
    Feb 25, 2015 at 7:20

0

You must log in to answer this question.

Browse other questions tagged .