Archive for the ‘IIS + PowerShell’ Category

It will be handy to reset the IIS from one server to all. Save it as ps1 and execute in admin account.

$servers = Get-SPServer | Where {$_.Role -ne “Invalid” }
foreach ($server in $servers) {
Write-Host “Restarting IIS on server $server…”
IISRESET $server.Address /noforce
Write-Host “IIS status for server $server”
IISRESET $server.Address /status


Read Full Post »

To begin IIS administration from Powershell, use the following command,

PS <path>Import-Module WebAdministration

If you find any error, proceed with below Set-ExecutionPolicy command

By default the “Execution Policy” powershell is “Restricted“. So that means if you just run the import command or WebAdministration, you will get an Exception from powershell. We can set the this policy to “RemoteSigned” that will allow your custom scripts to be run but will not allow any internet downloaded script which is not trusted.

PS <Local_Path> Set-ExecutionPolicy RemoteSigned

and proceed with Yes

and now try PS <path>Import-Module WebAdministration

and now you are succeed ! ! 🙂

To advance, try listing possible IIS PowerShell commands,

PS <path>get-command

PS <path>get-command -pssnapin WebAdministration

Read Full Post »