Did you ever encountered a situation where Get-WMIObject tells you that the access is denied?
The last week I’ve been doing a lot with PowerShell and IIS, where this is not such an uncommon issue 😉
For example:
1 2 3 4 5 6 |
Get-WmiObject -ComputerName IIS01 -Namespace "root\microsoftiisv2" -Query "select * from IISWebInfo" Get-WmiObject : Access denied At line:1 char:14 + Get-WmiObject <<<< -Namespace 'root\webadministration' -List -ComputerName IIS01 + CategoryInfo : NotSpecified: (:) [Get-WmiObject], ManagementException + FullyQualifiedErrorId : System.Management.ManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand |
The solution is on the Authentication parameter to the Get-WMIObject cmdlet:
1 2 3 4 5 6 7 8 9 10 |
-Authentication<AuthenticationLevel> Specifies the authentication level to be used with the WMI connection. Valid values are: -1: Unchanged 0: Default 1: None (No authentication in performed.) 2: Connect (Authentication is performed only when the client establishes a relationship with the application.) 3: Call (Authentication is performed only at the beginning of each call when the application receives the request.) 4: Packet (Authentication is performed on all the data that is received from the client.) 5: PacketIntegrity (All the data that is transferred between the client and the application is authenticated and verified.) 6: PacketPrivacy (The properties of the other authentication levels are used, and all the data is encrypted.) |
Now this gives us a bunch of options, but when you use option 6 (PacketPrivacy) it the command will work like a charm:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
PS C:\> Get-WmiObject -ComputerName "IIS01" -Namespace "root\microsoftiisv2" -Query "select * from IISWebInfo" -Authentication 6 __GENUS : 2 __CLASS : IIsWebInfo __SUPERCLASS : CIM_LogicalElement __DYNASTY : CIM_ManagedSystemElement __RELPATH : IIsWebInfo.Name="W3SVC/INFO" __PROPERTY_COUNT : 7 __DERIVATION : {CIM_LogicalElement, CIM_ManagedSystemElement} __SERVER : IIS01 __NAMESPACE : root\microsoftiisv2 __PATH : \\IIS01\root\microsoftiisv2:IIsWebInfo.Name="W3SVC /INFO" Caption : Description : InstallDate : MajorIIsVersionNumber : 7 MinorIIsVersionNumber : 5 Name : W3SVC/INFO Status : |