Solved

Powershell WMI for IIS7/7.5 reporting

Posted on 2011-03-02
5
3,490 Views
Last Modified: 2012-05-11
Hello,

I have been tasked to put together a reporting script to gather several attributes from several IIS instances on several servers using several versions of IIS.  The script needs to be able to run from any location with a vanilla PowerShell configuration loaded.  I have it working fine and gathering all needed attribues using:

Get-WmiObject -Namespace "root\WebAdministration" -Class Site -Authentication PacketPrivacy -ComputerName x
Get-WmiObject -NameSpace "root\WebAdministration" -Class VirtualDirectory -Authentication PacketPrivacy -ComputerName x

I can find the site name, physical directory pathm log directory path, site binding information along with other details, but I cannot find the AppPoolID.

In IIS 6 I used to gather this with an ADSI connection or with System.DirectoryServices.DirectoryEntry("IIS://server/W3SVC/1/root") but this does not appear to work with a 7.5 instance not in compatability mode.

Where can I find the AppPoolID in the root\WebAdministration namespace?

Thank you.
0
Comment
Question by:omnipower321
  • 3
5 Comments
 
LVL 10

Expert Comment

by:wls3
ID: 35024556
The site class only returns this set of properties:

__GENUS                   
__CLASS                   
__SUPERCLASS              
__DYNASTY                 
__RELPATH                 
__PROPERTY_COUNT          
__DERIVATION              
__SERVER                  
__NAMESPACE               
__PATH                    
ApplicationDefaults       
Bindings                  
FtpServer                 
Id                        
Limits                    
LogFile                   
Name                      
ServerAutoStart           
TraceFailedRequestsLogging
VirtualDirectoryDefaults

Open in new window

 

The VirtualDirecory class returns this set of properties:

__GENUS          
__CLASS          
__SUPERCLASS     
__DYNASTY        
__RELPATH        
__PROPERTY_COUNT 
__DERIVATION     
__SERVER         
__NAMESPACE      
__PATH           
AllowSubDirConfig
ApplicationPath  
LogonMethod      
Password         
Path             
PhysicalPath     
SiteName         
UserName

Open in new window

     

To get a broader search, try using the namespace \microsoftiisv2 with the class iiswebserversetting.  The properties pulled back by this search will return these fields:

__GENUS
__CLASS
__SUPERCLASS
__DYNASTY
__RELPATH
__PROPERTY_COUNT
__DERIVATION
__SERVER
__NAMESPACE
__PATH
AccessExecute
AccessFlags
AccessNoPhysicalDir
AccessNoRemoteExecute
AccessNoRemoteRead
AccessNoRemoteScript
AccessNoRemoteWrite
AccessRead
AccessScript
AccessSource
AccessSSL
AccessSSL128
AccessSSLFlags
AccessSSLMapCert
AccessSSLNegotiateCert
AccessSSLRequireCert
AccessWrite
AdminACLBin
AllowKeepAlive
AllowPathInfoForScriptMappings
AnonymousPasswordSync
AnonymousUserName
AnonymousUserPass
AppAllowClientDebug
AppAllowDebugging
AppFriendlyName
AppOopRecoverLimit
AppPoolId
AppWamClsid
AspAllowOutOfProcComponents
AspAllowSessionState
AspAppServiceFlags
AspBufferingLimit
AspBufferingOn
AspCalcLineNumber
AspCodepage
AspDiskTemplateCacheDirectory
AspEnableApplicationRestart
AspEnableAspHtmlFallback
AspEnableChunkedEncoding
AspEnableParentPaths
AspEnableSxs
AspEnableTracker
AspEnableTypelibCache
AspErrorsToNTLog
AspExceptionCatchEnable
AspExecuteInMTA
AspKeepSessionIDSecure
AspLCID
AspLogErrorRequests
AspMaxDiskTemplateCacheFiles
AspMaxRequestEntityAllowed
AspPartitionID
AspProcessorThreadMax
AspQueueConnectionTestTime
AspQueueTimeout
AspRequestQueueMax
AspRunOnEndAnonymously
AspScriptEngineCacheMax
AspScriptErrorMessage
AspScriptErrorSentToBrowser
AspScriptFileCacheSize
AspScriptLanguage
AspScriptTimeout
AspSessionMax
AspSessionTimeout
AspSxsName
AspTrackThreadingModel
AspUsePartition
AuthAdvNotifyDisable
AuthAnonymous
AuthBasic
AuthChangeDisable
AuthChangeUnsecure
AuthFlags
AuthMD5
AuthNTLM
AuthPassport
AuthPersistence
AuthPersistSingleRequest
AzEnable
AzImpersonationLevel
AzScopeName
AzStoreName
Bindings
CacheControlCustom
CacheControlMaxAge
CacheControlNoCache
CacheISAPI
Caption
CertCheckMode
CGITimeout
ClusterEnabled
ConnectionTimeout
ContentIndexed
CreateCGIWithNewConsole
CreateProcessAsUser
DefaultDoc
DefaultDocFooter
DefaultLogonDomain
Description
DirBrowseFlags
DirBrowseShowDate
DirBrowseShowExtension
DirBrowseShowLongDate
DirBrowseShowSize
DirBrowseShowTime
DisableSocketPooling
DisableStaticFileCache
DoDynamicCompression
DontLog
DoStaticCompression
EnableDefaultDoc
EnableDirBrowsing
EnableDocFooter
EnabledProtocols
EnableReverseDns
FrontPageWeb
HttpCustomHeaders
HttpErrors
HttpErrorsExistingResponse
HttpExpires
HttpPics
LogExtFileBytesRecv
LogExtFileBytesSent
LogExtFileClientIp
LogExtFileComputerName
LogExtFileCookie
LogExtFileDate
LogExtFileFlags
LogExtFileHost
LogExtFileHttpStatus
LogExtFileHttpSubStatus
LogExtFileMethod
LogExtFileProtocolVersion
LogExtFileReferer
LogExtFileServerIp
LogExtFileServerPort
LogExtFileSiteName
LogExtFileTime
LogExtFileTimeTaken
LogExtFileUriQuery
LogExtFileUriStem
LogExtFileUserAgent
LogExtFileUserName
LogExtFileWin32Status
LogFileDirectory
LogFileLocaltimeRollover
LogFilePeriod
LogFileTruncateSize
LogOdbcDataSource
LogOdbcPassword
LogOdbcTableName
LogOdbcUserName
LogonMethod
LogPluginClsid
LogType
MaxBandwidth
MaxBandwidthBlocked
MaxConnections
MaxEndpointConnections
MaxRequestEntityAllowed
MimeMap
Name
NTAuthenticationProviders
PassportRequireADMapping
PasswordCacheTTL
PasswordChangeFlags
PasswordExpirePrenotifyDays
PoolIdcTimeout
ProcessNTCRIfLoggedOn
Realm
RedirectHeaders
RevocationFreshnessTime
RevocationURLRetrievalTimeout
ScriptMaps
SecureBindings
ServerAutoStart
ServerBindings
ServerCommand
ServerComment
ServerListenBacklog
ServerListenTimeout
ServerSize
SetHostName
SettingID
ShutdownTimeLimit
SSIExecDisable
SSLAlwaysNegoClientCert
SslCtlIdentifier
SslCtlStoreName
SSLStoreName
TraceUriPrefix
UploadReadAheadSize
UseDigestSSP
UseHostName
Win32Error

Open in new window


Within this set of data you can find a lot of good info.  Also, check out my blog post, particularly about using the PSBase and PSBase.GetRelated() sections.  You can get a lot of very interesting relationships within the classes this way and do not have to be stuck within a single class:

http://learningpcs.blogspot.com/2010/11/wmic-namespace.html

Using this namespace, I can find a good bit, but, not all of the info you're after:

gwmi -namespace root\microsoftiisv2 -class "iiswebserversetting" -filter "servercomment='Powershell Site'" | select name, path, logfiledirectory, bindings, apppoolid | ft -auto

Open in new window

0
 

Author Comment

by:omnipower321
ID: 35025667
Thank you for the response.  I am able to get the data I need from the microsoftiisv2 namespace in IIS6 or 7 in compatibility mode, but it is an invalid namespace on IIS7/7.5 in "regular mode".  Same as the adsi.
0
 
LVL 2

Expert Comment

by:garrett_boarder
ID: 35031896
Not sure if you are going in blind or not but this tool has been very useful for me building WMI scripts around Primal Forms.  http://thepowershellguy.com/blogs/posh/archive/2007/03/22/powershell-wmi-explorer-part-1.aspx
0
 

Accepted Solution

by:
omnipower321 earned 0 total points
ID: 35060220
Was able to get the information needed out of:

namespace root\WebAdministration class Site
namespace root\WebAdministration class VirtualDirectory
namespace root\WebAdministration class Application

I had to use common attributes between them to match them up.
0
 

Author Closing Comment

by:omnipower321
ID: 35115331
Data was only available in root/webadministration for native IIS 7/7.5 where as it was combined in the site object in microsoftiisv2.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now