1
votes

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
1
I would suspect that the respective namespace or class doesn't exist in the 32-bit environment. You can enumerate namespaces with something like this: function List-WmiNamespaces {Get-WmiObject -Namespace $args[0] -Class '__namespace' | ForEach-Object {$ns = '{0}\{1}' -f $_.__Namespace, $_.Name; $ns; List-WmiNamespaces $ns}}; List-WmiNamespaces 'root\microsoft', and the classes in a namespace like this: Get-WmiObject -Namespace 'root\Microsoft\SqlServer' -List | Select-Object -Expand Name.Ansgar Wiechers
I indeed installed 64-bit SQL Server. But these two scripts get the same result both on 64-bit and 32-bit PowerShell. That is both "root\Microsoft\SqlServer\ComputerManagement13" and ServerSettingsGeneralFlag exist.luqiang tian

1 Answers

0
votes

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'"
}