I have a problem with a script. I check for firmware type and after that I format the hard drive based on that. The problem is that I get an error when it runs the command
New-Partition -DiskNumber 0 -GptType '{ebd0a0a2-b9e5-4433-87c0-68b6b72699c7}' $partsize_param -DriveLetter C
It says
a positional parameter cannot be found that accept argument '-UseMaxiumSize' + categoryinfo : invalidargument: (:) [New-Partition], ParameterBindingException + fullyqualifiederror: PositionalParameterNotFound, New-Partition
The funny thing is that the command runs just fine if I'm using -UseMaximumSize
instead of $partsize_param
Can someone point what is the error that I'm making?
function clean_install_hdd () {
Switch (Get-BiosType) {
1 {$firmwaremode='Legacy BIOS'}
2 {$firmwaremode='UEFI Mode'}
Default {$firmwaremode='Unknown'}
}
Get-Disk
$PartitionSize = Read-Host "Partition size - How many GB or max to use all available space"
if ("$PartitionSize" -eq "max") {
$partsize_param = '-UseMaximumSize'
} else {
$partsize_param = '-Size ' + $PartitionSize
}
if ("$firmwaremode" -eq "Legacy BIOS") {
Clear-Disk 0 -RemoveData -RemoveOEM -Confirm:$false; Initialize-Disk 0 -PartitionStyle MBR -Confirm:$false
New-Partition -DiskNumber 0 -$partsize_param -DriveLetter C -IsActive | Format-Volume -FileSystem NTFS -NewFileSystemLabel Windows -ShortFileNameSupport $False -Confirm:$false
}
if ("$firmwaremode" -eq "UEFI Mode") {
Clear-Disk 0 -RemoveData -RemoveOEM -Confirm:$false; Initialize-Disk 0 -PartitionStyle GPT -Confirm:$false
$systemPart = New-Partition -DiskNumber 0 -GptType '{c12a7328-f81f-11d2-ba4b-00a0c93ec93b}' -Size 100MB -DriveLetter S
& format.com "$($systemPart.DriveLetter):" /FS:FAT32 /Q /Y | Out-Null
New-Partition -DiskNumber 0 -GptType '{e3c9e316-0b5c-4db8-817d-f92df00215ae}' -Size 128MB
Write-Host $partsize_param
New-Partition -DiskNumber 0 -GptType '{ebd0a0a2-b9e5-4433-87c0-68b6b72699c7}' $partsize_param -DriveLetter C | Format-Volume -FileSystem NTFS -NewFileSystemLabel Windows -ShortFileNameSupport $False -Confirm:$false
}
}