diff --git a/scripts/iisControls.ps1 b/scripts/iisControls.ps1 new file mode 100644 index 0000000..c6222a5 --- /dev/null +++ b/scripts/iisControls.ps1 @@ -0,0 +1,46 @@ +param ( + [string]$ServerName, + [string]$AppPoolName, + [string]$StopOrStart +) + +write-host $StopOrStart +if ($StopOrStart -eq "stop") { + Invoke-Command -ComputerName $ServerName -Credential $cred -ScriptBlock { + param($AppPoolName) + + Import-Module WebAdministration + Write-Host "Stopping AppPool '$AppPoolName' on $($env:COMPUTERNAME)" + + try { + Stop-WebAppPool -Name $AppPoolName -ErrorAction Stop + + Start-Sleep -Seconds 2 + $state = (Get-WebAppPoolState -Name $AppPoolName).Value + Write-Host "Result: $state" + } catch { + Write-Error $_.Exception.Message + exit 1 + } +} -ArgumentList $AppPoolName +} + +if ($StopOrStart -eq "start"){ + Invoke-Command -ComputerName $ServerName -Credential $cred -ScriptBlock { + param($AppPoolName) + + Import-Module WebAdministration + Write-Host "Starting AppPool '$AppPoolName' on $($env:COMPUTERNAME)" + + try { + Start-WebAppPool -Name $AppPoolName + Start-Sleep -Seconds 2 + $state = (Get-WebAppPoolState -Name $AppPoolName).Value + Write-Host "Result: $state" + } catch { + Write-Error $_.Exception.Message + exit 1 + } +} -ArgumentList $AppPoolName +} +