1 | initial version |
I posted this question thinking that had encountered a permission or elevated privilege problem. It seems that this is natural behaviour for 'Format-Volume'. The following code snippet is based on a solution from StackOverflow and does not generate the pop-up. This code has been modified to format multiple additional disks.
[char]$highestDriveLetterInUse = ( ( Get-Volume ).DriveLetter | Sort-Object -Descending )[0]
[char]$nextDriveLetter = [int]$highestDriveLetterInUse + 1
[int]$dataDiskCount = 1
$rawDiskList = Get-Disk | Where-Object PartitionStyle -eq "RAW"
$rawDiskList | Format-Table -AutoSize
foreach( $rawDisk in $rawDiskList ){
# https://stackoverflow.com/a/42622812/8469997
Initialize-Disk -Number $rawDisk.Number -PartitionStyle MBR -confirm:$false
if ( 1 -eq $rawDiskList.Length ){ $fileSystemLabel = "Data" } else { $fileSystemLabel = "Data_${dataDiskCount}" }
New-Partition -DiskNumber $rawDisk.Number -UseMaximumSize -IsActive | Format-Volume -FileSystem NTFS -NewFileSystemLabel $fileSystemLabel -confirm:$False
Set-Partition -DiskNumber $rawDisk.Number -PartitionNumber 1 -NewDriveLetter $nextDriveLetter
[char]$nextDriveLetter = [int]$nextDriveLetter + 1
}
Formatting a disk using PowerShell without prompting for confirmation https://stackoverflow.com/a/42622812/8469997