I'm doing something that seems pretty basic to me but is not working as expected.
If the script is run with the -WhatIf switch then $liveTest should be "Test". If the script is run with the -Live switch then $liveTest should be "Live".
However both switches are causing $liveTest to be "Test"
param (
[CmdletBinding()]
[Parameter(Mandatory = $true, ParameterSetName = 'UsersOnlyLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'UsersOnlyTest')]
[Switch]
$users,
[Parameter(Mandatory = $true, ParameterSetName = 'ComputersOnlyLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'ComputersOnlyTest')]
[Switch]
$computers,
[Parameter(Mandatory = $true, ParameterSetName = 'AllLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'AllTest')]
[Switch]
$all,
[Parameter(Mandatory=$true)]
[string]
$days,
[switch]
$console,
[Parameter(Mandatory = $true, ParameterSetName = 'AllTest')]
[Parameter(Mandatory = $true, ParameterSetName = 'UsersOnlyTest')]
[Parameter(Mandatory = $true, ParameterSetName = 'ComputersOnlyTest')]
[switch]
$WhatIf,
[Parameter(Mandatory = $true, ParameterSetName = 'AllLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'UsersOnlyLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'ComputersOnlyLive')]
[switch]
$live
)
Process {
# If -WhatIf or -Live switch is passed, creates a hashtable for the -WhatIf parameter.
If($WhatIf) {
$whatIf = @{ WhatIf = $true }
$liveTest = "Test"
}
ElseIf($live) {
$whatIf = @{ WhatIf = $false }
$liveTest = "Live"
}
If($liveTest = "Test"){Write-Output $liveTest}
elseif($liveTest = "Live"){Write-Output $liveTest}
}

If($liveTest = "Test")needs to becomeIf($liveTest -eq "Test")