Files
logistics_support_tool/scripts/iisControls.ps1

50 lines
1.3 KiB
PowerShell

param (
[string]$ServerName,
[string]$AppPoolName,
[string]$StopOrStart
)
# Example string to run with the parameters in it.
# .\iisControls.ps1 -ServerName "usmcd1vms036" -AppPoolName "LogisticsSupportTool" -StopOrStart "stop"
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
}