Balpreet Patil
Balpreet Patil

Reputation: 1764

Get-WmiObject -query return nothing/null

I'm running this in powershell

PS C:\>Get-WmiObject -query "select * from  Win32_OptionalFeature where name = 'RemoteServerAdministrationTools-Roles-AD-Powershell'"

On my Windows 7 machine I'm getting correct output

__GENUS          : 2
__CLASS          : Win32_OptionalFeature
__SUPERCLASS     : CIM_LogicalElement
__DYNASTY        : CIM_ManagedSystemElement
__RELPATH        : Win32_OptionalFeature.Name="RemoteServerAdministrationTools-Roles-AD-Powershell"
__PROPERTY_COUNT : 6
__DERIVATION     : {CIM_LogicalElement, CIM_ManagedSystemElement}
__SERVER         : TTL001343
__NAMESPACE      : root\cimv2
__PATH           : \\TTL001343\root\cimv2:Win32_OptionalFeature.Name="RemoteServerAdministrationTools-Roles-AD-Powershell"
Caption          : Active Directory Module for Windows PowerShell
Description      :
InstallDate      :
InstallState     : 2
Name             : RemoteServerAdministrationTools-Roles-AD-Powershell
Status           :

But when I run this same command on Windows 2008 Server box in virtual environment, I get empty out put. Any idea why?

Note: in both machines I'm running powershell in Admin mode.

Upvotes: 1

Views: 3915

Answers (2)

Balpreet Patil
Balpreet Patil

Reputation: 1764

After getting crazy for a day. I found I should be using this command for Windows 2008 Server.

PS C:\>import-module servermanager
PS C:\>$feature=get-windowsfeature RSAT-AD-PowerShell

Now I can use it like this

PS C:\> $feature.Installed
True

Helpful links:

Windows 2008 http://technet.microsoft.com/en-us/library/ee662309.aspx

Windows 2012 http://technet.microsoft.com/library/jj205467(v=wps.620).aspx

Upvotes: 1

Mike Shepard
Mike Shepard

Reputation: 18186

I would run this:

gwmi Win32_OptionalFeature | sort-object -Property Name | select-object Name

And see if the feature in question is there with a slightly different name.

As was noted in the comment, RSAT might not be enabled at all, which would impact what you're seeing

Upvotes: 3

Related Questions