I have added data disks to Azure virtual machines and I need to create a volume for them.
I have used the following code to create the volume:
$disk = Get-Disk | where-object PartitionStyle -eq "RAW"
$disk | Initialize-Disk -PartitionStyle GPT
$partition = $disk | New-Partition -UseMaximumSize -DriveLetter F
$partition | Format-Volume -Confirm:$false -Force
While creating the volume, it asks for confirmation before formatting the disk.
I want to avoid this confirmation box. I tried -Confirm:$false -Force
but it still prompts for confirmation.
To format the drive type in Clear-Disk -Number X -RemoveData replacing X with your drive number. Click Y and press Enter to erase the drive. You will see a splash screen and return to an empty line in Powershell when completed.
The Initialize-Disk cmdlet initializes a Disk object with the RAW partition style to either the MBR or GPT partition styles. The default partition style is GPT. Disks must be initialized before they can be formatted and used to store data.
This fixed my problem. Confirmation popup does not appears while using the following code.
$disk = Get-Disk | where-object PartitionStyle -eq "RAW"
Initialize-Disk -Number $disk.Number -PartitionStyle MBR -confirm:$false
New-Partition -DiskNumber $disk.Number -UseMaximumSize -IsActive | Format-Volume -FileSystem NTFS -NewFileSystemLabel "Local Disk" -confirm:$False
Set-Partition -DiskNumber $disk.Number -PartitionNumber 1 -NewDriveLetter F
It appears this may be a bug with how Format-Volume
handles -Confirm as discussed here: https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/11088429-format-volume-force-parameter-does-not-work
The workaround suggested is to set $confirmpreference = 'none'
before you start.
You might also want to grab the current $confirmpreference in to a variable first and then put it back to what it was afterwards. E.g:
$disk = Get-Disk | where-object PartitionStyle -eq "RAW"
$disk | Initialize-Disk -PartitionStyle GPT
$partition = $disk | New-Partition -UseMaximumSize -DriveLetter F
$currentconfirm = $confirmpreference
$confirmpreference = 'none'
$partition | Format-Volume -Force
$confirmpreference = $currentconfirm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With