Format a drive using PowerShell without asking for confirmation

I added data disks for Azure virtual machines, and I need to create a volume for them.

I 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  

When creating a volume, it asks for confirmation before formatting the disk.

I want to avoid this confirmation window. I tried -Confirm:$false -Force, but it still asks for confirmation.

+4
source share
2 answers

This fixed my problem. A confirmation pop-up does not appear when 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  
+2
source

, , Format-Volume -Confirm, : https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/11088429-format-volume-force-parameter-does-not-work

$confirmpreference = 'none' .

$confirmpreference , , . :

$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 
+1

Source: https://habr.com/ru/post/1671571/


All Articles