Microsoft Virtualization Discussions

-NoPrompt or -Force for a few commands

jurphville
4,793 Views

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

Invoke-NaSnapmirrorRelease

Invoke-NaSnapmirrorBreak

Remove-NaSnapshot

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.

3 REPLIES 3

jausch
4,793 Views

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"

Alex

cknight
4,793 Views

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

jurphville
4,793 Views

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!

Public