Skip to content

Should Get-Member behave differently in Strict Mode? #9181

@HumanEquivalentUnit

Description

@HumanEquivalentUnit

In normal mode, accessing a property that does not exist returns $null. StrictMode disables this and makes it an exception. That is consistent over several commands - except Get-Member which returns $null. This is surprising, and I expected it should also raise an exception. Should it?

Test cases:

PS C:\> Set-StrictMode -Version 2
PS C:\> $x = Get-Item 'C:\windows'
PS C:\> $x.pretend
The property 'pretend' cannot be found on this object. # PropertyNotFoundStrict

PS C:\> $x | Select-Object -ExpandProperty pretend
Select-Object : Property "pretend" cannot be found # ExpandPropertyNotFound

PS C:\> $x | ForEach-Object -MemberName pretend
ForEach-Object : The input name "pretend" cannot be resolved to a member. # PropertyOrMethodNotFound

PS C:\> $x | Where-Object -Property pretend -eq $null
Where-Object : The input name "pretend" cannot be resolved to a property. # PropertyNotFound

PS C:\> $x.foreach('pretend')
The property 'pretend' cannot be found on this object. # PropertyNotFoundStrict

PS C:\> $x | Get-Member -Name pretend    # outputs $null

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions