Probably this question has been answered before.... but I have not found a specific answer to my needs.
BTW I\'m using PowerShell 3
Well, I\'m new in PowerShell
Two options to create object with methods:
Code samples:
$person | Add-Member -MemberType ScriptMethod -Value {
'I do stuff!'
}
$person = New-Module -AsCustomObject -ScriptBlock {
$Property = 'value'
[string]$Other = 'Can be strongly typed'
function MyMethod {
'I do stuff!'
}
}
EDIT: speaking of private/ public... In latter example property won't show up "by default". You can decide what is public using Export-ModuleMember
and specify -Variable
(properties) and/or -Function
(methods) that will be public. Without explicit Export-ModuleMember
it will behave same as in "normal" module - export only functions (methods).