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.
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.
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) :))))
Microsoft MVP – IIS