This is running on “end-user” machines They do not have admin rights.
No existing ps window exists. I’m firing this from a scheduled task. If I run the command from a dos window, or an existing ps window, no new window is shown. Firing from a scheduled task however, opens a blank powershell window while the task is running. Christopher Catlett Consultant | Detroit [MCTS_2013_small] Sogeti USA Office 248-876-9738 |Fax 877.406.9647 26957 Northwestern Highway, Suite 130, Southfield, MI 48033-8456 www.us.sogeti.com<http://www.us.sogeti.com/> From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On Behalf Of Kelley, Matthew Sent: Thursday, January 23, 2014 5:06 PM To: 'powershell@lists.myitforum.com' Subject: RE: [powershell] Any way of running a powershell script from a scheduled task, silently? Start-Job allows you to start a background job. That may work for you but I think that job dies if you close the session you launched it with. I use this for background scripts: #---- first create an encoded command---- # To use the -EncodedCommand parameter: $command = 'dir "c:\program files" ' $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) $encodedCommand = [Convert]::ToBase64String($bytes) powershell.exe -encodedCommand $encodedCommand powershell -noprofile -NoExit -command "&{start-process powershell -ArgumentList ' -NoExit -encodedCommand $($encodedCommand)' -verb RunAs -WindowStyle Hidden}" You will see a new powershell.exe process running in task manager, but the window will not be visible and will persist even if you close the powershell window you used to issue the command. You will have to accept the “run as admin prompt” if you start this command from a non-privileged powershell window or with a .bat or .cmd file. IF you put this in a batch file, make sure you cut/paste the actual encoded command and not the variable $encodedCommand since that variable would not necessarily be populated when the batch file runs. So like this: powershell -noprofile -NoExit -command "&{start-process powershell -ArgumentList ' -NoExit -encodedCommand ZABpAHIAIAAiAGMAOgBcAHAAcgBvAGcAcgBhAG0AIABmAGkAbABlAHMAIgAgAA==' -verb RunAs -WindowStyle Hidden}" I use this to start jobs at boot time on my machine to monitor or change things based on WMI events. Mostly fix the stuff that gets messed when GPO policies are applied! Matt From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com] On Behalf Of Daniel Ratliff Sent: Thursday, January 23, 2014 4:42 PM To: 'powershell@lists.myitforum.com'; 'powershell@lists.myitforum.com' Subject: RE: [powershell] Any way of running a powershell script from a scheduled task, silently? What's your current cmd? -Daniel Ratliff -----Original Message----- From: christopher.catl...@us.sogeti.com<mailto:christopher.catl...@us.sogeti.com> [christopher.catl...@us.sogeti.com<mailto:christopher.catl...@us.sogeti.com>] Sent: Thursday, January 23, 2014 03:34 PM Eastern Standard Time To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com> Subject: [powershell] Any way of running a powershell script from a scheduled task, silently? I am running a script regularly to set some user settings, if it sees a particular piece of hardware present on the system. I’ve tried the “–WindowStyle Hidden” and the “-NonInteractive” switches and they do not hide the powershell dialog. A blank, blue window, is shown. I’d really rather not have to wrap it inside a batch or vbscript. This is a script running on Win8.1 machines, so v4 is available. Christopher Catlett Consultant | Detroit [MCTS_2013_small] Sogeti USA Office 248-876-9738 |Fax 877.406.9647 26957 Northwestern Highway, Suite 130, Southfield, MI 48033-8456 www.us.sogeti.com<http://www.us.sogeti.com/> ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 The information transmitted is intended only for the person or entity to which it is addressed and may contain CONFIDENTIAL material. If you receive this material/information in error, please contact the sender and delete or destroy the material/information. ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ********************************************************** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1
<<inline: image001.jpg>>