I have a script which works when it is manually executed the script works under these conditions:
1) I start start.ps1 which then elevates with admin user then executes main.ps1 script
2) the start.ps1 is being run without any rights and I am elevating it by using
Start-Process -FilePath Powershell -LoadUserProfile -Credential $credential -ArgumentList '-File', $script
Everything works fine, please note that new powershell window appear and main.ps1 is being executed there.
now, when I create a scheduled task, then run it - I can see in the task manager that main.ps1 is being executed but noting is happening apart from task being stuck in scheduler. I cant use admin user in task scheduler it has to be executed as non privileged user.
Do you have any ideas how to fix this issue?
I have tried running it under local user, with/or without execution policy set to bypass/unrestricted etc nothing helped.
Thanks in advance