Using StrictMode, how can we filter the objects in the pipeline, when some of them don’t have the property set? When the Object doesn’t have the property set we get the error “The input name “xxxx” cannot be resolved to a property”
If we force the property on the Select-Object statement, the property is always present. But if we need to select all the properties and force the property we want to fiter on, we get an error saying “the property “xxxx” already exists”.
I can bypass this using the ErrorAction Ignore on the Select-Object command. Is this the only way to do it?
Set-StrictMode -Version Latest # Two AD Accounts UserWithMailbox, UserWithoutMailbox $x = Get-ADUser -filter 'samaccountname -like "User*"' -Properties * $x | Where-Object HomeMDB -ne $null | Select-Object SamAccountName, HomeMDB # Where-Object : The input name "HomeMDB" cannot be resolved to a property. $x | Select -Property HomeMDB, * | Select-Object SamAccountName, HomeMDB # Select : The property cannot be processed because the property "homeMDB" already exists $x | Select HomeMDB, HomeMDB -ErrorAction Ignore | Select-Object SamAccountName, HomeMdb # Create new Object with the property HomeMDB Allways Set $y = $x | Select HomeMDB, * -ErrorAction Ignore $y.HomeMDB.count