Al Polden
Al Polden

Reputation: 920

How to list all virtual directories for a IIS6 web site using WMI with powershell?

I've looked at this question Getting all virtual directories for a IIS6 web site using WMI but it doesn't answer my question.

I can get a list of the web sites but not the applications or virtual directories in them. I've tried the following.

Get-WmiObject  -class "IIsWebServerSetting" -namespace "root\microsoftiisv2" | select-object __SERVER, ServerComment, Name 
Get-WmiObject  -class "IIsWebVirtualDir" -namespace "root\microsoftiisv2" | select-object __SERVER, ServerComment, Name, Path, DefaultDoc
Get-WmiObject  -class "IIsWebVirtualDirSetting" -namespace "root\microsoftiisv2" | select-object __SERVER, ServerComment, Name, Path, DefaultDoc

None of these retrieve a list of virtual directories.

I can see the virtual directories in the metabase.xml file

<IIsWebVirtualDir   Location ="/LM/W3SVC/1653786949/root/PBSNET2005/GUI"
        AccessFlags="AccessExecute | AccessRead | AccessScript"
        AppFriendlyName="ClientServicesGUI"

The reason why i requires this is because i want to use a green/blue deployment process. To determine which version to update i need to find out what the current version is. I will use the physical path of the virtual directory to do this.

Does anyone have an alternative method of obtain the physical path of a virtual directory? Has anyone ever queried or updated the metabase.xml file directly?

Upvotes: 4

Views: 7081

Answers (2)

Al Polden
Al Polden

Reputation: 920

You need to specify the path to the virtual directory. Virtual directories further down the folder tree are not returned by WMI. Here is the powershell function if anyone requires it.

function Get-VirtualDirectoryPhysicalPathUsingWMI ([string]$server,[string]$siteName,[string]$vDirName,[string]$pathToVDir)
    {
        Invoke-Command $server -Script { param($siteName,$vDirName,$pathToVDir) 
            $iisWmiObj = Get-WmiObject -Namespace 'root\MicrosoftIISv2' -Class IISWebServerSetting -Filter "ServerComment = '${siteName}'"
            $objIIS = new-object System.DirectoryServices.DirectoryEntry("IIS://localhost/" + $iisWmiObj.Name + $pathToVDir )
            $directories = $objIIS.psbase.children
            $vDir = $directories.find($vDirName, "IIsWebVirtualDir")

            return $vDir.path
            } -Args $siteName,$vDirName,$pathToVDir

       #Get-VirtualDirectoryPhysicalPathUsingWMI  "pbsdevmaintws02" "Default Web Site" "GUI" "/Root/PBSNET2005"
    }

Upvotes: 0

Webplanet TFS Consulting
Webplanet TFS Consulting

Reputation: 1269

Try this:

gwmi -Namespace "root/MicrosoftIISv2" -Query "SELECT * FROM IIsWebVirtualDirSetting" | select name,path,AppFriendlyName

Upvotes: 3

Related Questions