# Run as Administrator $targetDisks = 0, 1 $minSize = 1MB foreach ($diskNumber in $targetDisks) { $disk = Get-Disk -Number $diskNumber -ErrorAction SilentlyContinue if (-not $disk) { Write-Host "Disk $diskNumber not found." continue } # Initialize disk if it is RAW if ($disk.PartitionStyle -eq 'RAW') { Write-Host "Disk $diskNumber is RAW. Initializing as GPT..." Initialize-Disk -Number $diskNumber -PartitionStyle GPT -PassThru | Out-Null # Refresh the disk object $disk = Get-Disk -Number $diskNumber } # Check for unallocated space $largestFreeExtent = Get-Disk $diskNumber | Get-PartitionSupportedSize -ErrorAction SilentlyContinue if ($largestFreeExtent.SizeMax -gt $minSize) { Write-Host "Unallocated space found on Disk $diskNumber. Creating partition..." # Create new partition and assign drive letter $partition = New-Partition -DiskNumber $diskNumber -UseMaximumSize -AssignDriveLetter # Label the volume with the disk number $volumeLabel = "NewVolume$diskNumber" # Format the volume as NTFS Format-Volume -Partition $partition -FileSystem NTFS -NewFileSystemLabel $volumeLabel -Confirm:$false Write-Host "Partition created and formatted on Disk $diskNumber as drive $($partition.DriveLetter):\" } else { Write-Host "No sufficient unallocated space on Disk $diskNumber." } }