Run PowerShell Script does not work with SCCM 2012 R2 SP1

Hello,

After the update to SCCM 2012 R2 SP1 all PowerShell Scripts will result the exit code 1...
I use the Task Sequence integrated "Run PowerShell Script" with the option "Bypass". Even if I run a ps1-file with the following code it ends with exit code 1:

$hostname = hostname
write-host $hostname

smsts.log Shows:

Executing command line: Run Powershell script
TESTCLIENT001
Process completed with exit code 1 
Command line returned 1 
ReleaseSource() for C:\_SMSTaskSequence\Packages\PS1000E1. 
reference count 1 for the source C:\_SMSTaskSequence\Packages\PS1000E1 before releasing
Released the resolved source C:\_SMSTaskSequence\Packages\PS1000E1 
Process completed with exit code 1 
!--------------------------------------------------------------------------------------------! 
Failed to run the action: TEST PS SCRIPT.
Incorrect function. (Error: 00000001; Source: Windows) 
Set authenticator in transport 
Set a global environment variable _SMSTSLastActionRetCode=1
Set a global environment variable _SMSTSLastActionSucceeded=false 
Clear local default environment
Failed to run the action: TEST PS SCRIPT. Execution has been aborted

Is there anyone else who has this issue? Is this maybe a bug? Any ideas?

Thank you.

Patrik

June 18th, 2015 3:38am

I've had no issues. Can you please post a screenshot of your TS as a sanity check.
Free Windows Admin Tool Kit Click here and download it now
June 18th, 2015 7:31pm

Hi  Jason

It's a very basic TS - just for testing this issue.

June 19th, 2015 2:35am

And test.ps1 is in the specified package and the package has been properly distributed (and is up to date) on an accessible DP?
Free Windows Admin Tool Kit Click here and download it now
June 19th, 2015 2:13pm

Same problem here. In our case we're running a powershell script thats calling an external ".exe" program. In this case the "Run PowerShell Script" will always result the exit code 1. The problem exists since updated to SCCM 2012 R2 SP1.

As a workaround you can run your powershell script in a "Run Command Line" step:

powershell.exe -ExecutionPolicy ByPass -nologo -noprofile -file <YourFile>
Jonathan

June 23rd, 2015 2:27am

Before the upgrade, back when you had SCCM 2012 R2, what was the outcome, were you getting other exit codes like 0?
Free Windows Admin Tool Kit Click here and download it now
June 23rd, 2015 9:15am

Before the upgrade, back when you had SCCM 2012 R2, what was the outcome, were you getting other exit codes like 0?

The outcome before SP1 was always exit code 0.

Before Upgrade in a "Run PowerShell Script" step:
Exit Code=0

After Upgrade in a "Run PowerShell Script" step:
Exit Code=1 and Incorrect function in smsts.log

As mentioned in the previous post: If we run the same script in a "Run Command Line" step, everything works as expected (Exit Code=0).

June 23rd, 2015 9:30am

That is interesting. I wanted to double check your results. We are beginning to investigate migrating to SP1. Even though SMTS reports exit code 1, does the script actually execute?

-Tony

Free Windows Admin Tool Kit Click here and download it now
June 23rd, 2015 9:42am

That is interesting. I wanted to double check your results. We are beginning to investigate migrating to SP1. Even though SMTS reports exit code 1, does the script actually execute?

-Tony

Yes, it does.

As I metioned: This problem only occurs if you're calling an external application within the script.

Example

This is always working:

Try {
    "$(get-date) - Before" | Out-File "C:\windows\Logs\TestPS_NonExternal.log" -Append
    "$(get-date) - After" | Out-File "C:\windows\Logs\TestPS_NonExternal.log" -Append
} Catch {
    # Return with Exit Code 0
    Exit 0
}

This is not working in a "Run PowerShell Script" since updated to SP1 (=> the ts step fails even so the script is exectued):

Try {
    "$(get-date) - Before" | Out-File "C:\windows\Logs\TestPS_External.log" -Append
    schtasks.exe /End /TN "Some Task"
     "$(get-date) - After" | Out-File "C:\windows\Logs\TestPS_External.log" -Append
} Catch {
    # Return with Exit Code 0
    Exit 0
}

- Jonathan

June 23rd, 2015 10:06am

Yes, it does.

As I metioned: This problem only occurs if you're calling an external application within the script.

Not for me! I have this issue with every script. It does not depend on calling an external application in my case. If you read my very first post, you see that I only used the following code:

$hostname = hostname
write-host $hostname

And it also ends with exit code 1. However like you already mentioned: The script runs successfully, it just ends with exit code 1 altough everything were executed successfully...

The workarround (Run as CMD) is in my opinion just a temporary solution... I want to solve it, so that I can use the RunPowershell Script Step again without worrying about that.

Free Windows Admin Tool Kit Click here and download it now
June 24th, 2015 4:29am

Yes, it does.

As I metioned: This problem only occurs if you're calling an external application within the script.

Not for me! I have this issue with every script. It does not depend on calling an external application in my case. If you read my very first post, you see that I only used the following code:

$hostname = hostname
write-host $hostname

And it also ends with exit code 1. However like you already mentioned: The script runs successfully, it just ends with exit code 1 altough everything were executed successfully...

The workarround (Run as CMD) is in my opinion just a temporary solution... I want to solve it, so that I can use the RunPowershell Script Step again without worrying about that.

"hostname" is an external application. if you use $env:computername instead of "hostname" in your example it should work.

But I'm agree with you. It's a bug and MS should fix this problem.

June 24th, 2015 5:59am

"hostname" is an external application. if you use $env:computername instead of "hostname" in your example it should work.

You are absolutly right. "hostname" is an external application of course. So I can confirm, the following:

RunPowershell Script ends with Exit code 1 if it calls an external command like hostname.exe / schtasks.exe / a.s.o.! Altough it ends with Exit code 1 it completes all content included in the script successfully.

Workarround:
Run the script in a "Run Command Line" step -> everything will work as expected (Exit Code=0).

Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 3:30am

"hostname" is an external application. if you use $env:computername instead of "hostname" in your example it should work.

You are absolutly right. "hostname" is an external application of course. So I can confirm, the following:

RunPowershell Script ends with Exit code 1 if it calls an external command like hostname.exe / schtasks.exe / a.s.o.! Altough it ends with Exit code 1 it completes all content included in the script successfully.

Workarround:
Run the script in a "Run Command Line" step -> everything will work as expected (Exit Code=0).

July 6th, 2015 7:28am

I can also confirm that this is an issue that did not exist before SP1. I'm also running R2 SP1 and have been using a powershell script to check for active computer associations. It has been working for a year... upgraded to SP1 yesterday and problem popped up.
Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 3:50pm

So you should open a case at Microsoft so that the product group is aware of that behavior.
July 29th, 2015 3:52pm

We opened a call a couple of days ago. It is confirmed as a bug and product groups received a bug report. Will be fixed I think...

Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 4:00pm

We opened a call a couple of days ago. It is confirmed as a bug and product groups received a bug report. Will be fixed I think...

  • Proposed as answer by Sebastian Zolg Wednesday, July 29, 2015 7:56 PM
July 29th, 2015 7:56pm

We opened a call too. First the issue was not "global". After a couple of days MS replied that the bug is confirmed and is not an isolated issue. Now they reported that it will be fixed in the "update roll up". When that will be is not known by me.

I hope to get a repons to that question anytime.

Free Windows Admin Tool Kit Click here and download it now
August 4th, 2015 7:40am

CU1 was released today, but I did not find a reference for this issue. -Tony
August 4th, 2015 5:08pm

Thanks for the tips.

I didn't change it to use "Run command Line" >>> I just put a tick on "Continue on error" seems to work for me as well because as you mentioned the script already ran successfully.

Free Windows Admin Tool Kit Click here and download it now
August 10th, 2015 9:54pm

Did CU1 fix?

Running into a similar issue where I can run a ps1 as a SCCM program but only on Windows 10, Win7 x64 returns exit code 1. Tried a ton of stuff just not getting anywhere.


  • Edited by J_Systems 17 hours 58 minutes ago
August 17th, 2015 9:51am

Not fixed. We havent tested, but KB is not mentioning it and in addition I asked the escalation engineer. He said its not fixed. 

Cheers

Free Windows Admin Tool Kit Click here and download it now
August 17th, 2015 9:54am

Did CU1 fix?

Running into a similar issue where I can run a ps1 as a SCCM program but only on Windows 10, Win7 x64 returns exit code 1. Tried a ton of stuff just not getting anywhere.


  • Edited by J_Systems Monday, August 17, 2015 1:49 PM
August 17th, 2015 1:49pm

Hi

expecting to results from MS as well... same issue with ps1

Free Windows Admin Tool Kit Click here and download it now
September 9th, 2015 7:33am

We also are experiencing the same issue here. Is there any update on this issue? A fix?

Thanks,

WiM

September 14th, 2015 8:11am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics