PrimalScript 2014 - PowerShell V3 Packger Error

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
clum09
Posts: 149
Joined: Thu Apr 24, 2008 9:11 am

PrimalScript 2014 - PowerShell V3 Packger Error

Post by clum09 » Fri Aug 22, 2014 12:37 pm

Hello,

I have a script to shutdown the computer running Windows Server 2012 R2. The code is listed below:

Code: Select all

Stop-Computer -Force
When I packaged the script with "SAPIEN PowerShell V3 Host (Command line) Any platform" or "SAPIEN PowerShell V3 Host x64" engine type, the packaged script produced the following error:

ERROR: Stop-Computer : Privilege not held.
ERROR: At line:35 char:1
ERROR: + Stop-Computer -Force
ERROR: + ~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (MYCOMPUTERNAME:String) [Stop-C
ERROR: omputer], ManagementException
ERROR: + FullyQualifiedErrorId : StopComputerException,Microsoft.PowerShell.Comma
ERROR: nds.StopComputerCommand
ERROR:

However, when I packaged the script with "SAPIEN PowerShell V2 Host (Command line) Any platform" or "SAPIEN PowerShell V2 Host x64" engine type, the packaged script worked as expected - it can shutdown the computer without any problem.

This is also true with the code listed below from: http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Code: Select all

$computername= "."
$win32OS = get-wmiobject win32_operatingsystem -computername $computername
$win32OS.psbase.Scope.Options.EnablePrivileges = $true
$win32OS.win32shutdown(8)
Currently, I ended up with using the shutdown utility from Windows to perform this task.

Please let me know what I can do for the Stop-Computer cmdlet with work with PowerShell V3 packager.

Thanks.

User avatar
clum09
Posts: 149
Joined: Thu Apr 24, 2008 9:11 am

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by clum09 » Fri Aug 22, 2014 12:44 pm

By the way, this behavior also happens with PrimalScript 2012 - extactly the same issue with SAPIEN PowerShell Host (Command line) with "Use PowerShell V3" engine type selected, but not when "Use PowerShell V3" engine type is not selected.

Thanks.

User avatar
Alexander Riedel
Posts: 7021
Joined: Tue May 29, 2007 4:43 pm

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by Alexander Riedel » Fri Aug 22, 2014 2:37 pm

As the error message indicates, the process does not have the privilege to execute that statement.
We cannot debug or determine your local security settings.
This error is reported by the powershell engine and not by the packager or the host inside the package.

Most likely you will need to elevate to obtain the proper privilege to execute that statement.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
clum09
Posts: 149
Joined: Thu Apr 24, 2008 9:11 am

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by clum09 » Fri Aug 22, 2014 4:19 pm

Alex,

This command (Stop-Computer -Force) was launched in PowerShell V3 packaged script within an Administrator console's command prompt window.

What other elevated privilege can it be above an Administrator console?

When I just launched this cmdlet in the Administrator PowerShell console without a script, the computer will shutdown without any issue. Again, this command is launched on a Windows Server 2012 R2 computer.

When I packaged this script with the PowerShell V2 engine, the packaged script can shutdown the same computer (Windows Server 2012 R2) without any problem.

Are you saying that the PowerShell V2 engine provided a higher elevated privilege than a PowerShell V3 engine?

Why the shutdown utility from Windows Server 2012 R2 can shutdown the computer in the same Administrator command prompt?

User avatar
Alexander Riedel
Posts: 7021
Joined: Tue May 29, 2007 4:43 pm

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by Alexander Riedel » Fri Aug 22, 2014 9:08 pm

It may have something to do with the "any platform" engine. It seems the powershell engine has issues with assemblies not tied to a specific platform.
We are investigating the problem.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
clum09
Posts: 149
Joined: Thu Apr 24, 2008 9:11 am

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by clum09 » Wed Aug 27, 2014 11:44 am

Thank you for the information.

By the way, this behavior also happens with Power Studio 2014 - exactly the same issue with SAPIEN PowerShell V3 Host (Command line) x64 platform packager.

User avatar
clum09
Posts: 149
Joined: Thu Apr 24, 2008 9:11 am

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by clum09 » Mon Sep 22, 2014 5:54 am

Alex,

Any news for the packaging issue with PowerShell V3 packager?

Thanks.

User avatar
Alexander Riedel
Posts: 7021
Joined: Tue May 29, 2007 4:43 pm

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by Alexander Riedel » Tue Sep 23, 2014 2:18 pm

This has nothing to do with the packager.
A little research on Google shows that there is a difference between .NET 4.0 and prior regarding the SE_SHUTDOWN_NAME privilege.

The process token needs to be adjusted for a process to have the right to shutdown a computer. PowerShell.exe does that for you, because it is a system management console.

Packaged executables do NOT have that privilege set and we will not add that per default, because it would open the door do a great number of security problems.

This post has some C# code showing how to adjust token privileges:
http://stackoverflow.com/questions/1793 ... ng-to-shut

If you really positively MUST use stop-computer from a packaged executable I suggest you incorporate code like that.

This blog post might help:
http://www.leeholmes.com/blog/2010/09/2 ... owershell/
Alexander Riedel
SAPIEN Technologies, Inc.