Page 1 of 1

PrimalScript 2014 - PowerShell V3 Packger Error

Posted: Fri Aug 22, 2014 12:37 pm
by clum09
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.

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Posted: Fri Aug 22, 2014 12:44 pm
by clum09
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.

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Posted: Fri Aug 22, 2014 2:37 pm
by Alexander Riedel
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.

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Posted: Fri Aug 22, 2014 4:19 pm
by clum09
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?

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Posted: Fri Aug 22, 2014 9:08 pm
by Alexander Riedel
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.

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Posted: Wed Aug 27, 2014 11:44 am
by clum09
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.

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Posted: Mon Sep 22, 2014 5:54 am
by clum09
Alex,

Any news for the packaging issue with PowerShell V3 packager?

Thanks.

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Posted: Tue Sep 23, 2014 2:18 pm
by Alexander Riedel
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/