Jan
4
Written by:
Richard Siddaway
Friday, January 04, 2008 10:06 AM
If you were at IT Forum in Barcelona in November 2006 you will remember the key note speech in which some PowerShell cmdlets were demonstrated administering IIS 7. Really good demo. Sadly it doesn't look like the cmdlets are going to make it into the final version.
A managed code (.NET) API is provided that gives access to the management functionality of IIS 7. As it is .NET we can use this from PowerShell. A few examples have already been published notably
http://blogs.iis.net/tobintitus/archive/2006/11/30/powershell-and-microsoft-web-administration.aspx
http://blogs.iis.net/tobintitus/archive/2006/12/01/more-on-iis-7-administration-with-powershell.aspx
http://www.iis.net/articles/view.aspx/IIS7/Use-IIS7-Administration-Tools/Scripting-IIS7/An-Introduction-to-Windows-PowerShell-and-IIS7
http://www.iis.net/articles/view.aspx/IIS7/Use-IIS7-Administration-Tools/Scripting-IIS7/Writing-PowerShell-Command-lets-for-IIS7
These examples assume that you are working on the local machine. This started me thinking about how I can do this remotely as I don't want to have to keep copying the same script to multiple machines or keep logging into multiple machines. PowerShell + remote machines means using V2.
First off install PowerShell V2 on to your IIS machine. I'm using a Windows 2008 RC0 Web edition virtual machine. We want to be able to load the appropriate assemblies into PowerShell on the remote machine and then run a number of commands. This means we need to create a PowerShell runspace on the remote machine otherwise each command effectively will run in a fresh instance of PowerShell.
$rsweb1 = New-Runspace -Computername rc0web
Invoke-Expression -Runspace $rsweb1 { [system.reflection.assembly]::loadfrom("c:\windows\system32\inetsrv\microsoft.web.administration.dll") }
We then load the assembly into the runspace
Invoke-Expression -runspace $rsweb1 { $server2 = New-object microsoft.web.administration.servermanager }
We can then create the servermanager object
Invoke-Expression -runspace $rsweb1 { $server2 | get-member}
will give us access to the properties and methods of that object. I did try creating the servermanager object on the local machine but the serialisation\deserialisation that is involved in the transport means that the properties are returned but not the methods.
Having got our connection to the server it is time to start doing something useful - like creating a site. The documentation for these .NET classes is a bit awkward to navigate especially as the functionality isn't always where you would expect it to be. To reprise last time we get a connection to the IIS server object as follows
$rsweb1 = New-Runspace -Computername rc0web
Invoke-Expression -Runspace $rsweb1 { [system.reflection.assembly]::loadfrom("c:\windows\system32\inetsrv\microsoft.web.administration.dll") }
Invoke-Expression -runspace $rsweb1 { $server2 = New-object microsoft.web.administration.servermanager }
Invoke-Expression -runspace $rsweb1 { $server2 }
We can now start to do some work - lets create a site. The sites are actually a collection and we need to use the Add() method of the sitecollection class - hence my earlier comment about the documentation being difficult. The onlin documentation on the MSDN site is the best I have found so far.
## to add a site
Invoke-Expression -runspace $rsweb1 { $server2.Sites.Add("Demo", "http", "*:80:demo.manticore.org", "c:\inetpub\demo") }
Invoke-Expression -runspace $rsweb1 { $server2.CommitChanges() }
The parameters we pass to Add() are respectively the name of the site, the protocol (could also use https), the binding information - which in this case says listen on all IP addresses, on port 80 and the site is demo.manticore.org - and finally the path to the virtual directory. The new site isn't actually created until we use the CommitChanges() method of the server object.
Stopping and starting a site is very simple
## to stop a site
Invoke-Expression -runspace $rsweb1 { $server2.sites["Demo"].Stop() }
## to start a site
Invoke-Expression -runspace $rsweb1 { $server2.sites["Demo"].Start() }
Removing a site is fairly straight forward
## to remove a site
Invoke-Expression -runspace $rsweb1 { $site = $server2.sites["Demo"] }
Invoke-Expression -runspace $rsweb1 { $server2.sites.Remove($site) }
Invoke-Expression -runspace $rsweb1 { $server2.CommitChanges() }
We just get a variable representing the site, pass it into the remove() method and call CommitChanges()
These changes can easily be scripted enabling the same changes to be applied to sites across a web farm. The same script could be used to copy the files into a newly created web site giving us the very powerful provisioning engine for our web farms. The only real issue is creating the runspaces and remembering to remove them when we are finished
Continuing our look at IIS 7 and PowerShell its time to move on to applications and applications. First we get our connection to the IIS 7 server then creating an application is performed as follows
$rsweb1 = New-Runspace -Computername rc0web
Invoke-Expression -Runspace $rsweb1 { [system.reflection.assembly]::loadfrom("c:\windows\system32\inetsrv\microsoft.web.administration.dll") }
Invoke-Expression -runspace $rsweb1 { $server2 = New-object microsoft.web.administration.servermanager }
To add an application ie something we would access as www.manticore.org/wtest1 - we get site into which we want to create the application, Add the application by name and point to the directory with the files and then commit the changes
## to add an application
Invoke-Expression -runspace $rsweb1 { $site = $server2.sites["Default Web Site"] }
Invoke-Expression -runspace $rsweb1 { $site.Applications.Add("/WTest1", "c:\inetpub\wtest1")}
Invoke-Expression -runspace $rsweb1 { $server2.CommitChanges() }
Application pools can contain 1 or more applications and can be used to isolate applications on a web server. Again simple to create with PowerShell - get the applicationpool collection and add a new one
## to add an application pool
Invoke-Expression -runspace $rsweb1 { $server2.ApplicationPools.Add("WTest1") }
Invoke-Expression -runspace $rsweb1 { $server2.CommitChanges() }
Finally we want to use the new application pool with the new application
## to add an application pool to an application
## note that the application pool name has to be exactly right including case !!!
Invoke-Expression -runspace $rsweb1 { $server2 = New-object microsoft.web.administration.servermanager }
Invoke-Expression -runspace $rsweb1 { $app = $server2.Sites["Default Web Site"].Applications["/Wtest1"] }
Invoke-Expression -runspace $rsweb1 { $app.ApplicationPoolName = "WTest1" }
Invoke-Expression -runspace $rsweb1 { $server2.CommitChanges() }
After creating the applicationpool it is a good idea to refresh the server object. We get the application and change the name of the applicationpool associated with it. If we are dealing with a site with only the root application then use
Invoke-Expression -Runspace $rsweb1 { $app = $server2.Sites["NewSite"].Applications[0] }
As with most things PowerShell and .NET related similar patterns of usage are found as you dig further into the detail. This short article should be a good starting point for administering IIS 7 remotely with PowerShell.
This use of Powershell and simple .NET code gives us a method of administering IIS 7 in a remote scenario. There is also an IIS 7 WMI provider which I will investigate later. This whole idea of IIS 7 & PowerShell is getting interesting now and gives us another piece of the jigsaw for administering our environments with PowerShell which I will be talking about in February. Looks like I've just found some really good demo material!!!
7 comment(s) so far...
Re: PowerShell and IIS 7
Moreover, Liu Sword door who do one thing at home, that is, think of ways to kill mbt sabili! mbt sabili not a secret show in the day MBT Tenga Boots, was also the day of the show we all know that women hate, and get rid of the existence of such a trivial nature of willow house is no risk. Therefore, the Liu Yuan Liu sent home to show to hook up within days of his disciples were an attempt to start from the inside, I did not expect seeing done, Liu Yuan actually disappeared.
By yinhu on
Thursday, March 17, 2011 7:30 AM
|
Re: PowerShell and IIS 7
http://www.powershellcommunity.org/Blogs/CommunityBlogs/tabid/55/EntryId/2/Welcome-to-the-community.aspx
By yinhu on
Saturday, March 26, 2011 7:41 AM
|
Re: PowerShell and IIS 7
If you buy Mbt shoes you will like cheap mbt shoesMen MBT Sandals
By yinhu on
Saturday, March 26, 2011 7:42 AM
|
Re: PowerShell and IIS 7
You just came Chanel Replicas across this really cool bumper sticker printing website that offers colorful, custom stickers at great prices. Unfortunately, Chanel Handbags you're just not sure that you want to put Chanel Bags a sticker of any kind on your Prada Handbags car. What reason would you have to do UGG so?
Trust us;Discount UGGs there are plenty of reasons to Prada Replicas smack one of these great stickers on your ride. The Prada Bags first of which is for a cause. UGGs Is there something that you feel particularly strong about? Are you completely against illegal Gucci Replicas immigration? Do you support organ and tissue donation? Are you a gun control advocate? Are you all about owning a firearm? Gucci Handbags These days there are plenty of things to be passionate UGG Boots on Sale about, from wars in foreign countries, to animal adoption. Gucci Bags People from your hometown to places on the opposite side of the country are promoting their causes with bumper sticker printing.UGG Boots
You don't want to let everyone know Louis Vuitton Replicas how you feel about the death penalty. That's okay! People are putting bumper stickers on their Christian Louboutin Shoes on Sale cars for other reasons too. Discount UGG Boots How about advertising? Do you own a business? Louis Vuitton Handbags Do you have a friend who owns a business? What about UGG Boots Outlet your parents? Individuals who own businesses are beginning to realize that it doesn't really make sense to pay for elaborate Louis Vuitton Bags and expensive advertising when you could just advertise on your own vehicle for essentially free. Bumper sticker advertising is not Discount UGG Boots only inexpensive, it's portable. If you're promoting your business from the back window of your car, then people from your house, to the mall, to the Coach Bags Outlet beach where you're planning to go this weekend will see your advertisement.UGG Boots on Sale Talk about Christian Louboutin Outlet reaching a mass market!
What about politics? Are you a Democrat who is against the new Republican congress and you're already dreaming Coach Handbags about campaigning for the future? Come up with a slogan and make it happen! Or, you can Cheap UGG Boots just promote the candidate with whom you most relate. If you're passionate about politics and you want to help your favorite candidate get the word out, a Coach Bags bumper sticker is definitely the way to go. Political stickers are almost as The North Face Outlet prevalent on the roadway as....cars! Christian Louboutin Shoes
Another type of sticker that's seen on Coach Outlet Online the roadways quite frequently is the sports team sticker. Show off your UGG Boots Volunteer Pride or your love for the Baltimore Orioles with a big, orange "T" or an "O" Discount Christian Louboutin Shoes that takes up half of the back window on your SUV. There are sports team stickers available everywhere online. If Cheap Christian Louboutin Shoes you aren't seeing one you love, a custom bumper sticker printing company can certainly produce one for you and it'll Coach Outlet be a bumper sticker you're proud to have on your car. The North Face Jackets
People also put stickers on North Face Jackets their cars for religious and spiritual reasons. From the Jesus fish, to the cross, people Coach Handbags Outlet are praising the Lord in the pew and on their bumper!
On a more somber note, people also use Coach Handbags bumper stickers to remember relatives and friends who have passed away.
If you're UGGs interested in ordering your Coach Bags Outlet own custom bumper sticker, you're making a great decision! Have a seat in front of your computer and visit a bumper sticker printing company's website. You can customize your own sticker Coach Bags or choose one from the thousands they have to offer. Don't just stop at one though! You can order stickers in bulk, which is especially handy if you're using your bumper stickers to promote your small business. Your Coach Outlet sticker order should ship The North Face Jacket within a couple of days and you'll be well on your way to showing off your cause, political affiliation, or favorite sports team! North Face Jacket
By swei on
Friday, October 14, 2011 6:28 AM
|
Re: PowerShell and IIS 7
Anyone blogging regularly Discount Vibram FiveFingers would love to increase their blog traffic. Targeted web Vibram Five Fingers on Sale traffic is what every webmaster craves. Cheap Christian Louboutin Shoes The process of getting your site or blog noticed by Vibram FiveFingers on Sale the search engines is often referred to as UGG SEO which stands for search engine Discount Vibram Five Fingers optimization.
When it comes to SEO there are 100's Vibram Five Fingers Outlet of methods, with in those 100's of methods Discount Christian Louboutin Shoes there are probably 1000's of strategies. The most popular method of SEO would have to be Vibram FiveFingers Link Building. Building quality Christian Louboutin Shoes on Sale one way links back to your site or blog Vibram FiveFingers Outlet can be very effective in getting UGGs the search engines attention, when done Vibram Five Fingers correctly.
I know, not Christian Louboutin Shoes everyone that's Blogging or doing any writing online Cheap UGG Boots for that matter, is doing it for a business purpose, I also know, it's a great hobby. A lot of people write Blue UGG Boots cause they feel they have a knack for it, but unfortunately no one can Christian Louboutin Outlet ever see it because it hasn't been Blue UGG Search Engine Optimized or to be a little more specific, Blue UGGs you need Backlinks. Yes, Backlinks is only part of the equation, but in my honest Red UGG opinion a solid Link Building Strategy can UGG Boots on Sale really get the search engines attention. Red UGG Boots
Think about this, you wouldn't be spending Red UGGs your valuable time working out or exercising if you knew you'd never UGG Gloves get results, so why are you Blogging/Writing, if only a handful of Discount UGGs people ever see it, you might as well just think it for that matter.
You need to get traffic to UGG Boots on Sale your Blogs and Articles if you'd like a chance of monetizing it. You can use UGG Gloves AdSense ad's or promote affiliate products to make some spare cash if your UGG Boots Blog is getting traffic too. It all comes back to traffic, and unless your paying for it, getting traffic is hard work. Building one way Backlinks to your Blog Discount UGG Boots is one of the most popular methods UGG Boots Outlet to increase Blog traffic.
You'd be surprised to know how many UGGs "Bloggers", holding no more than a High School Diploma are "6 Figure Income - Expert Writers" now because some Big- Wig saw something special in their content. Blogging is awesome, I still write at least a post a day. Nothing is Sand UGG Boots worse than pouring your heart into something Sand UGG and getting nothing out of it.
Quick Personal Experience... Sand UGGs
I love the NFL, I know a lot Navy UGG Boots about it and it's fun for me to Green UGGs write about it. When I first started Blogging I couldn't get 10 visitors a day, and it killed me because I knew Navy UGG I had a lot to offer. I knew that anyone that actually Black UGG Boots knew football would really enjoy my Blog, but I Discount UGG Boots couldn't get it to anyone. Finally I read a report about Green UGG Boots Link Building strategies and I got to work. After about Green UGG 6 weeks of blood sweat and tears and building Backlinks nearly 24/7 the traffic started to roll in. Now, I enjoy writing about the NFL weekly and it results in a steady income Black UGGs for me. Is it making me rich, no far from it, just knowing my writing is what I thought it Navy UGGs was and people are willing to pay me UGG Boots for it, has been very gratifying. Black UGG
By swei on
Thursday, December 15, 2011 7:34 AM
|
NFL Jerseys
Many have been influenced to put on New York Giants Jerseys. If they see someone wearing a jerseys, these people then lease the rights to use the jerseys and begin to questions such as how much you paid for it? In which you understand? There are some people that can often wearing the NFL Jerseys Cheap in the streets or in school. It is not surprising the jerseys for men are larger, the company create many. It is very good for business, and get significant gains, there are many customers buy them just because they may be less expensive. Danny Ware Jersey wholesale is the development of affordable products and souvenirs, but usually not as elegant as the real data.High quality,plus low price,it is perfect that is exactly what we need or what we have is.The design and diverse of Patrick Chung Jersey are our want to.
By nianxi on
Thursday, February 02, 2012 7:07 AM
|
Cheap Timberland Boots
There are so many kinds of Cheap True Religion Jeans for you to choose. So Cheap Louis Vuitton Handbags it's not easy to choose a Buy Jordan Shoes suitable pair of Cheap Puma Shoes . I think Cheap New Era Hats a pair of jeans Cheap Tiffany & Co Jewellery true religion is a good choice Cheap Oakley Sunglasses. That's what I'm talking about jeans: ED Hardy Hats to create her debut in Cheap Chanel Jewelry Los Angeles, California Wholesale Timberland Boots in 2002 and jeans Cheap Puma Shoes just begun. Today,Cheap Timberland Boots they offer a full line of jeans not only,Air Jordan 11 Cheap but shirts, Cheap Kobe Bryant Shoes, jackets, shirts and Air Jordan 26 Cheap other accessories. A feature of this brand of Air Max 90 Cheap jeans hiragana character "hello", a Japanese Cheap Gucci Shoes syllabary as "Chi" Supra Skytop Shoes is expressed.
The words Ferrari Puma Shoes used to describe the Wholesale Oakley Sunglasses true religion jeans Air Max 95 Cheap, the "hippies", "Chic", Timberland Boots Sale "Timeless" and "Czech Republic". There is concern for the quality of products manufactured by the true religion Cheap Tiffany Jewelry is also a section on the site, which Wholesale Gucci Handbags is in the case of counterfeit goods,Louis Vuitton Replica Handbags and that explains it. Cheap Evisu Jeans offers for men, Puma Running Shoes women and children Cheap Air Force Ones in different styles. MLB Hats Cheap Bootcut trousers in men, Cheap Nike Shox R4 legs splayed, skinny jeans, Buy Oakley Sunglass the right leg, or corduroy.Tiffany Jewellery These jeans are made from Wholesale True Religion Jeans denim, to a variety of Air Jordan 13 Cheap colors and different Wholesale Tiffany Jewelry perspectives bays Oakleys Sunglasses. Most of Cheap NBA Jerseys these jeans look like Red Bull Hats they were made and broken for a comfortable fit. All of these Wholesale Air Max jeans, no matter what Cheap Supra Shoes the hardware looks Cheap Lacoste Shoes good with a pair of Cheap Nike Dunks sneakers or shoes.
But the price of Cheap Nike Shox the jeans a bit Cheap Frey Wille Jewelry higher than other Cheap LeBron James Shoes jeans, Wholesale Puma Shoes cheap jeans,Wholesale New Era Hats true religion is what we buy Supra Shoes Skytop in the future. I think New York Yankees Hats online shopping wholesale Monster Energy Hats is a good choice. Well,Buy Tiffany Jewelry there are so many places like this. In places Cheap Armani Sunglasses that we find true religion Puma Sandals jeans wholesale, we are much cheaper than buying individually. In addition, Cheap Chanel Handbags a large number of Chanel Silver Jewelry people who bought DC Hats jeans reliable information Supra TK Society Shoes to share.
By cawholesaler001 on
Tuesday, February 07, 2012 2:48 AM
|