Formatting a disk using PowerShell without prompting for confirmation
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
Stop-Service -Name ShellHWDetection$Disk = Get-Disk 2# $Disk | Clear-Disk -RemoveData -Confirm:$false$Disk | Initialize-Disk -PartitionStyle MBR$Disk | New-Partition -UseMaximumSize -DriveLetter T | Format-Volume -FileSystem NTFS -NewFileSystemLabel "DiskLevel" -Confirm:$false -ForceStart-Service -Name ShellHWDetectionAbove code worked for me Stop and Start of ShellHWDetection is the key here