waithidden { pathname of file ((it as string) of value “Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell” of native registry) } -ExecutionPolicy RemoteSigned -File C:\Software\Scripts\corpprints.ps1
pause while {exists running application “powershell.exe”}
I have tried every way under the sun to set this to ByPass the Execution Policy but nothing is working.
I have tried running this as a PowerShell script, action script. Tried changing the script around 10 different ways, making variables to hold the information to running the script as you would normally. I can run this script No issue from the desktop. It works just fine no issue from PowerShell. Only when i run it as a task does it fail like this.
The user running the task is a DomainAdamin as well. Not sure why its happening.
Does anyone have any ideas or tips to try? This would save me a lot of manual time if I could just add printers from the server through a task.
Normally we’d use -ExecutionPolicy Bypass when executing PowerShell scripts.
I’m not sure whether the script requires connecting to the print server, but keep in mind it’s executing as LocalSystem, not as the logged-on user, so it may have problems authenticating to the print server - but you’ll need to get the script to execute first anyway.
Just to be forewarned, you’re jumping in the deep end here. I haven’t had a case where I needed to supply a password for things like this, and if we did, it would be the end-user’s password on the client (since printer mappings are per-user, it doesn’t do any good to map it with one of your own accounts, the end-user wouldn’t see that).
You should probably use one of the overrides like runas=currentuser, so the PowerShell executes in that user’s context and you won’t need their password - but they do need to be logged on to the machine when your action executes.
Youre right. I was getting the feeling this isnt the best way. I will talk with my team mate and see where im going wrong internally. It may just be my novice experience affecting the action.
Thank you for the advice!
You don’t need to put the password in the actual action. In the below example, the only thing you really need to change is the account (leave password=required) and when you run the action it will prompt you for the actual password and it is not visible anywhere
Jason is right though - this is rare… I only ever needed this once for a very specific use case - in my situation the job needed to make connection to SQL database using Windows Authentication and running it with specific domain user was the easiest way to do it.
After fighting with this I was eventually able to get the issue worked out. Thanks to all your alls help!
I was over thinking it and making it way more complicated than it needed to be.