If I have a PS 5 class and I need a static member in it - how to declare it?
Class Foo { [string] $Bar = 'static member' }
So I could refer to it without an instance like this
Write-Host [Foo]::Bar
Is it possible?
PowerShell 5 added the static for this:
static
static [string] $Bar = 'static member'
Demo:
PS > class Foo { >> static [string] $Bar = 'static member' >> } PS > [Foo]::Bar static member PS >