I want PowerShell to throw an error when trying to select non-existing properties, but instead I get empty column as output. Example:
$ErrorActionPreference=
Something like this...?
$props = 'Id','ProcessName','xxx'
$availableProps = Get-Process *ex*|Get-Member -MemberType Properties | Select -ExpandProperty Name
$missingProps = $props | Where-Object {-not ($availableProps -contains $_)}
if ($missingProps) {
Write-Error "invalid property(s) $missingProps"
throw { [System.Management.Automation.PropertyNotFoundException] }
}
Get-Process *ex* | Select-Object $props