the interpreter will throw an exception if the referenced variable hasn’t been set yet.Let's see when that feature might come in handy.
PS> Set-PSDebug -OffAs you can see, with "Strict" mode off(well "Strict" flag is of type Switch, and all the Boolean flags were replaced with Switches), the PowerShell interpreter simple accepts the fact that function "add" just adds value of $x and $z without caring about what the value of $z is.
PS> function add($x, $y) { $x + $z }
PS> add 1 10
1
PS> $z = 100
PS> add 1 10
101
PS> Set-PSDebug -StrictAlthough the demo is really too simple of a case, in your scripts, you might have variables that you are not keeping track of but being still used somewhere in your scripts.
PS> ri function:add; rv z # remove "add" function and the variable $z
PS> function add($x, $y) { $x + $z }
PS> add 1 10
The variable $z cannot be retrieved because it has not been set yet.
At line:1 char:31
+ function add($x, $y) { $x + $z <<<< }
My.Types.MshxmlThen, as you see in Monad Technology Blog, load the newly created custom type data:<?xml version="1.0" encoding="utf-8" ?>
<Types>
<Type>
<Name>System.Security.SecureString</Name>
<Members>
<ScriptProperty>
<Name>UnsecureString</Name>
<GetScriptBlock>
[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($this))
</GetScriptBlock>
</ScriptProperty>
</Members>
</Type>
</Types>
Now, you can see that SecureString type has been extended with "UnsecureString".MSH>$admin = get-credential administrator
MSH>($admin.password).getType().fullName
System.Security.SecureString
MSH>$admin.password | get-member -MemberType ScriptProperty | format-list
TypeName : System.Security.SecureString
Name : UnsecureString
MemberType : ScriptProperty
Definition : System.Object UnsecureString {get=[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($this));}
where *** secret *** is your decoded password string.MSH>$admin.password
System.Security.SecureString
MSH>$admin.password.UnsecureString
*** secret ***
<IMPORTANT POINT>
Whenever you are adding some functions, you should make a conscious decision about whether those functions are best exposed as a "function" or as a "type extension".
</IMPORTANT POINT>
Experimenting with a different format of blogs...