Skip to content
Discussion options

You must be logged in to vote

Get-TypeData doesn't throw for unknown types in PS 7+ — it just returns $null. So the pattern is:

if (-not (Get-TypeData -TypeName 'MyNs.ClassName')) {
  Update-TypeData -TypeName 'MyNs.ClassName' -MemberName 'Foo' -MemberType ScriptProperty -Value { … }
}

No try/catch needed. If you're on 5.1, $null is still returned for unknown types there — the throwing behavior might be something else in your stack.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@SetTrend
Comment options

Answer selected by theJasonHelmick
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Resolution-Answered The question is answered.
3 participants