 <p>You can't (easily) use a variable as a parameter name. This is a good situation to use <a href="https://technet.microsoft.com/en-us/library/jj672955.aspx" rel="nofollow">variable splatting</a>. This lets you easily build a dynamic set of parameters in a hash table.</p> <pre><code>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" $Params = @{ DiskNumber = 0 DriveLetter = "C" }; if ($PartitionSize -eq "max") { $Params.Add("UseMaximumSize",$true); } else { $Params.Add("Size", $PartitionSize); } if ("$firmwaremode" -eq "Legacy BIOS") { Clear-Disk 0 -RemoveData -RemoveOEM -Confirm:$false; Initialize-Disk 0 -PartitionStyle MBR -Confirm:$false; $Params.Add("IsActive",$true); New-Partition @Params | 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 &amp; 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 $Params.Add("GptType","{ebd0a0a2-b9e5-4433-87c0-68b6b72699c7}"); New-Partition @Params | Format-Volume -FileSystem NTFS -NewFileSystemLabel Windows -ShortFileNameSupport $False -Confirm:$false } } </code></pre>