How do I load the Powershell module WebAdministraion?

rated by 0 users
This post has 1 Reply | 2 Followers

Top 500 Contributor
Posts 13
ewood Posted: 12-01-2011 3:19 PM

I'm trying to write a web application deployment script and want to use the stop-website and start-website comdlets, but I cannot successfully load the powershell module.  I have seen suggestions about adding as a snapin, but running the command

"add-pssnapin WebAdministration" fails with:

PS C:\Windows\SysWOW64\WindowsPowerShell\v1.0> add-pssnapin WebAdministration
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version
At line:1 char:13
+ add-pssnapin <<<<  WebAdministration
    + CategoryInfo          : InvalidArgument: (WebAdministration:String) [Add
   -PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad


I can right click on the powershell icon in the tool bar and select "import system module" and a powershll window will pop up, importing modules and I can use the cmdlets in question.  How do I import into a script for use?



Top 10 Contributor
Posts 658
Idera Employee

The confusion is that it first started out as a Snapin in IIS 7.0 but has morphed to a Module in IIS 7.5.

Use this code snippet to determine which version to use when deploying the script:

$hasSnapin = get-pssnapin | Select { $_.Name.toLower().Trim() = "webadministration" }
if ($hasSnapin -ne $null) {
  add-pssnapin WebAdministration
} else {
  import-module WebAdministration
Page 1 of 1 (2 items) | RSS
Copyright 2012 All rights reserved.