Stop IIS without confirmation box – Powershell


I’m trying to stop an iis site using PS, but also trying to skip the annoying confirmation box

If I run the following script accepting the confirmation it will stop it just fine

However if I add the cmdlet to set the confirmation as false it does not give me any error or the confirmation, but it doesn’t stop the site.

Any idea why?


The $false is being expanded when you pass the string to ArgumentList. Either use single quotes or escape the $ used in $false so it doesn’t get expanded until the child process executes:

The way you are doing it now causes the command to be rendered in the child PowerShell process as follows:

Note the missing $ after -Confirm:, but forcibly setting a [switch] state requires a [bool] type. $false is a [bool], but when rendered in a string like this it will be evaluated to the literal string false.

I’m surprised you aren’t getting an error though, since -Confirm:false throws a type conversion error. This could be explained if you have $ErrorActionPreference set to SilentlyContinue or Ignore elsewhere, but is more likely that the error is showing in the child process window quickly before the window closes.

This article explains variable expansion in strings in more detail if you want to know more.


Stop IIS without confirmation box – Powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply