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

iis-6powershellwmi

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?

Best Answer

Try this:

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