Objects assigned to variables
PowerShell (and all other .NET languages) has two main categories of types, value types and reference types.
A variable that holds a value type contains an instance of that type. Value types include numeric (int
, int64
, byte
, and so on), characters (char
), DateTime
, and so on. When a value type is used, for instance, by assigning it to another variable or using the variable as an argument for a parameter, the value is copied.
Reference types differ from value types. A variable assigned a reference type holds only the reference to that object (not the object itself). Two (or more) variables may reference the same object. Reference types are very common in PowerShell; examples include Hashtable
, PSCustomObject
, processes returned by Get-Process
, services returned by Get-Service
, and so on. When used as an argument for a parameter, the reference to the object is passed (the object is not copied).
A string is not a value type, but it has...