February 2019
Intermediate to advanced
626 pages
15h 51m
English
Many of the object types used in PowerShell are reference types. When an object is passed to a function, any changes made to that object will be visible outside the function, irrespective of the output generated by the command. For example, the following function accepts an object as input, then changes the value of a property on that object:
function Set-Value { [CmdletBinding()] param ( [PSObject]$Object ) $Object.Value = 2}
When the function is passed an object, the change can be seen on any other variables that reference that object:
PS> $myObject = [PSCustomObject]@{ Value = 1 }PS> Set-Value $myObjectPS> $myObject.Value2
Strings, numeric values, and dates, on the other hand, are all examples of value types. Changes ...
Read now
Unlock full access