Microsoft Virtualization Discussions

remove-navol help

corey
3,627 Views

Hi,

In my script I want to remove a list of volumes, and I want to do so without it prompting me with the "Are you sure you want to destroy..." message.

Here's the section of the script I am referring to:

foreach ($VOL in $vol_list)
{
Set-NaVol $VOL -offline | Remove-NaVol
}

However when I run this it prompts with the "Are you sure you want to destroy volume ..." and you need to answer "Y" or hit enter to continue, and again for every volume in the list.  How can I force this to just happen without user intervention?

Thanks,
Corey

1 ACCEPTED SOLUTION

egrigson1
3,627 Views

You can simply append -Confirm:$false to your Remove-NaVol command like so;

Set-NaVol $VOL -offline | Remove-NaVol -Confirm:$False

Obviously you want to be careful once that's in place as you won't get a second chance. You can test what would happen by using -WhatIf like so;

Set-NaVol $VOL -offline | Remove-NaVol -Confirm:$False -Whatif

Regards,

Ed.

View solution in original post

4 REPLIES 4

egrigson1
3,628 Views

You can simply append -Confirm:$false to your Remove-NaVol command like so;

Set-NaVol $VOL -offline | Remove-NaVol -Confirm:$False

Obviously you want to be careful once that's in place as you won't get a second chance. You can test what would happen by using -WhatIf like so;

Set-NaVol $VOL -offline | Remove-NaVol -Confirm:$False -Whatif

Regards,

Ed.

corey
3,627 Views

Fantastic!  That worked a charm.

Thanks heaps Ed

I do understand the dangers of this, but it is handy to know.

Cheers.

v_ovesny
3,627 Views

Hi,

Whe I use

Set-NaVol $VOL -offline | Remove-NaVol -Confirm:$False -Whatif

before:

Temper                online    80,0 GB0%80,0 GB  True     103     3M aggr3

after:

Temper                offline         00%      0 False       0      0 aggr3

Volume is not removed, only Offline state and information is 0.

When I use without -Confirm:$False -Whatif, VOL is removed OK.

Any Idea ?

JGPSHNTAP
3,627 Views

^^

Confused.. Do you know what -whatif does?

The command doesn't execute if you specify -whatif

The command should work fine with - Remove-NaVol -Confirm:$False

Public