luqiang tian
luqiang tian

Reputation: 67

Get-WmiObject can't be executed on PowerShell (x86) but on PowerShell

Why can I execute the following code on PowerShell but not on PowerShell (x86) on the same computer?

Get-WmiObject -Namespace "root\Microsoft\SqlServer\ComputerManagement13" -Class ServerSettingsGeneralFlag -Filter "FlagName='ForceEncryption'"

Exception:

At line:1 char:1 
+ Get-WmiObject -Namespace "root\Microsoft\SqlServer\ComputerManagement ...
    + CategoryInfo          : NotSpecified: (:) [Get-WmiObject], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Upvotes: 1

Views: 1103

Answers (1)

briantist
briantist

Reputation: 47802

As @AnsgarWiechers said, it likely doesn't exist. As for why, maybe you've installed 64 bit SQL Server and not 32 bit?

One way you might be able to work around this is with PowerShell remoting. If PowerShell remoting is enabled and configured, you can remote into your own machine from the 32 bit process, and you'll be connected to a 64 bit instance. So you can run this code to get your result from the 64 bit session.

$result64 = Invoke-Command -ComputerName . -ScriptBlock {
    Get-WmiObject -Namespace "root\Microsoft\SqlServer\ComputerManagement13" -Class ServerSettingsGeneralFlag -Filter "FlagName='ForceEncryption'"
}

Upvotes: 0

Related Questions