26 Jun 2013 @ 7:41 AM 

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:

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:

-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:

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                :
Posted By: Jeff Wouters
Last Edit: 26 Jun 2013 @ 07:41 AM

EmailPermalink
Tags
Categories: DuPSUG, PowerShell



 Last 50 Posts
 Back
Change Theme...
  • Users » 1
  • Posts/Pages » 328
  • Comments » 468
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About



    No Child Pages.

Contact



    No Child Pages.

Speaking



    No Child Pages.

Health Check



    No Child Pages.