I was recently trying to publish a powershell script via an SCCM Package / Program / Advertisement. My ‘bingfu’ and ‘googlefu’ was not working. I asked on the absolute best SCCM listserv run by http://myitforum.com (Rod Trent and company). Todd Hemsell provided the link below which was doing EXACTLY what I wanted.
http://www.patricktowles.com/2010/10/running-powershell-scripts-as.html
Of course, there is more to the story. However, my script was not working. I kept getting Error Code 1 in the execmgr.log on the client. One of the things unique to my environment is all servers are x64. SCCM client runs as 32 bit, which in turns run (x86) powershell, which resides below the c:windowssysWOW64 folder. We have scripts required to be AllSigned and set in the Group Policy administrative template. The GPO only sets the AllSigned on the 64 bit powershell I later found out. I manually set the execution policy (Set-ExecutionPolicy) to All Signed. Here is the registry entry to set.
HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftPowerShell1ShellIdsMicrosoft.PowerShell
You can set this setting via Preferences in Group Policy or manually set on the machine running Set-ExecutionPolicy within the (x86) powershell window to AllSigned Thanks to Todd and the list for putting me on the right track. Hopefully this helps someone else and what is %~dp0%1 (only syntax a programmer would love) :))))
Cheers,
Steve Schofield
Microsoft MVP – IIS
1 Comment
http:// said
I don't know if he updated his blog or not but the command
powershell -Command "& {Set-ExecutionPolicy -scope Currentuser -executionPolicy Unrestricted}"
which of course can be changed to whatever execution policy sets the policy for the current user (SCCM exec).