Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

PENDING Unable to run PowerShell in SCCM Package

  • Thread starter Thread starter pcb
  • Start date Start date
  • Replies Replies 5
  • Views Views 16K

pcb

Well-Known Member
Messages
45
Solutions
2
Reaction score
0
Points
6
We have been trying to run a powershell script as part of a package and have been unsuccessful getting anything to run. To test, I created a script with just one command - "pause" and verified that it runs on the target machine with the logged in user's rights. Then I created a package program like this:

1659455497155.png
I set the target machine execution policy to unrestricted and attempted to run it with user rights like this:
1659455600595.png
I set the schedule to run it at logon of any user and also checked the box to allow running it from the software center. CM attempts to run the script and the powershell window appears, but seems to crash. We get a very brief flash of red error text and the window closes. The execmgr log shows this:
1659455872380.png

I have tried every variation (running with admin rights, using a drive letter, using -ExecutionPolicy bypass in the command, etc) of this that I can think of with no success. In fact, I have never been able to get a powershell script to run anywhere except during a task sequence.

I have two questions:
1. has anyone here had sucess running powershell in a package or global condition?
2. Is there any way to get the actual error that is happening? CM reports it exits with error 1, but this isn't very helpful.

1659456406332.png
 
So I take from the lack of any replies that nobody uses powershell in sccm packages?
 
There are no tricking to running PowerShell using mecm. As long as your local policies allow it. It will run. Did you run you powershell script using the local system account on the system in question?
 
No I didn't manually run it with the system account, but I did run it manually with the local user and that was successful. As shown above, I have it set to run with the local user's rights from sccm, but it crashes.

The execution policy on the client is set to unrestricted for testing.

There is litterally only one command in the script - pause. I am just trying to get anything to run successfully from sccm before I continue with the real script.

I can load psexec and try the script locally in the system account, if you think that is necessary to prove the script works, but it seems to me that if I can run it manually with the logged in user and set sccm to "Run with user's rights" that should be the same context... right?
 
ok, so the answer is yes. The script runs successfully as system at the desktop of the computer in question. It starts and says "press any key to continue" as expected. When deployed to a collection or included in a task sequence, whether it is run as system or with user rights, it crashes.
 
ok, so the answer is yes. The script runs successfully as system at the desktop of the computer in question. It starts and says "press any key to continue" as expected. When deployed to a collection or included in a task sequence, whether it is run as system or with user rights, it crashes.

i use this command in the "Command Line" field instead and it never failed. give it a try

powershell.exe -executionpolicy Bypass -file ".\script.ps1"
 

Forum statistics

Threads
7,157
Messages
27,935
Members
18,237
Latest member
Causal

Latest posts

Back
Top