How to perform IISRESET with Powershell Script
You can do it with the Invoke-Command cmdlet:
invoke-command -scriptblock {iisreset}
UPDATE:
You can also simplify the command using the & call operator:
& {iisreset}
Having used & {iisreset}
with occasional failure lead me to this:
Start-Process "iisreset.exe" -NoNewWindow -Wait
Now it waits for iisreset.exe
to end gracefully.
This works well for me. In this application, I don't care about the return code:
Start-Process -FilePath C:\Windows\System32\iisreset.exe -ArgumentList /RESTART -RedirectStandardOutput .\iisreset.txtGet-Content .\iisreset.txt | Write-Log -Level Info
The Write-Log cmdlet is a custom one I use for logging, but you could substitute something else.