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 WebAdministrationAdd-PSSnapin : No snap-ins have been registered for Windows PowerShell version2.At line:1 char:13+ add-pssnapin <<<< WebAdministration + CategoryInfo : InvalidArgument: (WebAdministration:String) [Add -PSSnapin], PSArgumentException + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad dPSSnapinCommand
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?
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 }