Category Archives: Note To Self

Note To Self: using PowerShell to manage IIS 6


So since I always forget these neat things I learn, I’ve decided to make little notes to myself that can maybe help some others…

If you’d like to manage IIS using powershell its pretty easy if its version 7 since powershell is supported for that. If you have 6 or below, its not as straight forward, but still pretty easy using WMI.

The namespace you want is root\microsoftiisv2 (I’ve only tested this with iis 6, not sure if its different for older versions)

I recently needed to modify the username and passwords on a bunch of virtual directories and I found this to be a good way to update them all.

 

$vds = gwmi –namespace root\microsoftiisv2 –class iiswebvirtualdirsetting

This is the class for the virtual directory settings. A list of available classes can be found on MSDN Network or you can do it by asking gwmi

gwmi –namespace root\microsoftiisv2 -list

Personally I like MSDN for this.

Now once you get the data you need loaded up you can modify it easily enough, in my case i wanted to change the unc username and password, and luckily the virtual directories i needed to modify were in order so it was array indexes 24 through 157.

 

foreach ($i in 24..157){

$vds[$i].UNCUserName = “name”

$vds[$i].UNCPassword = “password”

$vds[$i].put()

}

 

and done!

to verify this you can do this:

 

$vds | ft name, path, uncusername, uncpassword

 

scary that’s saved in clear text huh?

Advertisements