I have a script to shutdown the computer running Windows Server 2012 R2. The code is listed below:
Code: Select all
Stop-Computer -Force
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)
Please let me know what I can do for the Stop-Computer cmdlet with work with PowerShell V3 packager.
Thanks.