Microsoft Virtualization Discussions

-NoPrompt or -Force for a few commands

The following commands require that a user confirm the operation before continuing...




I would like to be able to answer "yes" programmatically for these commands so the user is not prompted for each item.  Is that possible?

I see that each of these cmdlets have a -Confirm switch, but they seem to behave the same weather the switch is set or not.


Re: -NoPrompt or -Force for a few commands

Yes, the simplest way to do this is to use the $confirmpreference environment variable.  To turn off prompts completely, add the following to the top of your script:

$confirmpreference = "none"


Re: -NoPrompt or -Force for a few commands

You can also disable prompts on a per-cmdlet basis by specifying -Confirm:$false.

Re: -NoPrompt or -Force for a few commands

Thanks for the great suggestions.  I tried using -Confirm $false, but that didn't work...I was missing the colon syntax, -Confirm:$false works great.

I'm curious why that option defaults to $true?  I understand the reasoning from an administrative perspective...those are dangerous commands.  From from a programming perspective, if the default is $true, maybe there should be -NoConfirm switch to change it to false?

Thanks again for the help!

Cloud Volumes ONTAP
Review Banner
All Community Forums