In a module, I have the following function snippet:
function Get-InstalledSoftware { [CmdletBinding()] param ( [string[]]$Name, [string[]]$Publisher, [string[]]$Computername = 'localhost' ) begin { Write-Verbose "Initiating the $($MyInvocation.MyCommand.Name) function…"; if ($Name) { ## Allow asterisks in cmdlet but WQL requires percentage $Operator = @{ $true = 'LIKE'; $false = '=' }[$Name -match '\*'] $Name = $Name | foreach { $_.Replace('*', '%') } $WhereQuery += "(ARPDisplayName $Operator '$($Name -join "' OR ARPDisplayName $Operator '")') " } } }
I am passing the strings 'name*' and 'name' to the $Name param and $Operator is always null. I can recreate this in the console and it works as expected. If $Name has a * in it, $Operator is LIKE. If $name doesn't have a * in it, $Operator is =.
Can anyone shed some light on this?