I'm trying to write a server build script that includes Boolean parameters for various tasks, e.g. whether to install IIS. If the user does not specify this parameter one way or the other, I want the script to prompt for a decision, but for convenience and unattended execution I want the user to be able to explicitly choose to install IIS or NOT install IIS by setting the value to True or False on the command line and therefore avoid being prompted. My issue is that when I create a Boolean parameter, PowerShell automatically sets it to False, rather than leaving it null, if it wasn't specified on the command line. Here is the design that I THOUGHT would've worked:
param( [bool]$IIS ) if ($IIS -eq $null) { $InstallIIS = Read-Host "Do you want to install IIS? (Y/N)" if ($InstallIIS -eq "Y") {$IIS = $true} } if ($IIS) {Do stuff here} Any suggestions for how to achieve my desired outcome would be most appreciated. Then if this changes anything, what I'd REALLY like to do is leverage PSRemoting to accept these build decision parameters on the user's system host and then pass them to the targets as an ArgumentList, and I'm wondering if that will affect how these Booleans are handled. For example:
param ( [string[]]$Computers [bool]$IIS ) $Computers | Foreach-Object { Invoke-Command -ComputerName $_ -ArgumentList $IIS -ScriptBlock { param( [bool]$IIS ) if ($IIS -eq $null) { $InstallIIS = Read-Host "Do you want to install IIS? (Y/N)" if ($InstallIIS -eq "Y") {$IIS = $true} } if ($IIS) {Do stuff here} Ideas?