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”




and done!

to verify this you can do this:


$vds | ft name, path, uncusername, uncpassword


scary that’s saved in clear text huh?


About jrich

I am the Solutions Architect for Apex Learning in Seattle WA. I've been working with computers since I was 13. Started programming when I was 14. Had my first IT job as tech support at an ISP at the age of 15 and became a network admin at the age of 17. Since then I've worked at a variety of small to mid size companies supporting, maintaining and developing all aspects of IT. Mostly working with Windows based networks but have recently been working with Solaris system as well. I created this blog mostly as a place for me to take my own notes, but also share things that I had a hard time finding the info for.

Posted on July 20, 2010, in Note To Self and tagged , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: