Tutorial by Examples

class Person { [string] $FirstName [string] $LastName [string] Greeting() { return "Greetings, {0} {1}!" -f $this.FirstName, $this.LastName } } $x = [Person]::new() $x.FirstName = "Jane" $x.LastName = "Doe" $greeting = $x.Greeting() #...
5.0 In PowerShell 5.0+ you can list available constructors by calling the static new-method without parentheses. PS> [DateTime]::new OverloadDefinitions ------------------- datetime new(long ticks) datetime new(long ticks, System.DateTimeKind kind) datetime new(int year, int month, int d...
class Person { [string] $Name [int] $Age Person([string] $Name) { $this.Name = $Name } Person([string] $Name, [int]$Age) { $this.Name = $Name $this.Age = $Age } }
PS > Get-Member -InputObject $anObjectInstance This will return all members of the type instance. Here is a part of a sample output for String instance TypeName: System.String Name MemberType Definition ---- ---------- ---------- Clone ...
# Define a class class TypeName { # Property with validate set [ValidateSet("val1", "Val2")] [string] $P1 # Static property static [hashtable] $P2 # Hidden property does not show as result of Get-Member hidden [int] $P3 # Constructor Ty...
class ParentClass { [string] $Message = "Its under the Parent Class" [string] GetMessage() { return ("Message: {0}" -f $this.Message) } } # Bar extends Foo and inherits its members class ChildClass : ParentClass { } $Inherit = [ChildClass...

Page 1 of 1