Chaining Type Conversions

by Sep 9, 2010

In PowerShell, you can do multiple sequential type conversions. For example, you should first convert the string into a character array and then into the byte array to split a string into a byte array:

[Byte[]][Char[]]“Hello World!”

Now, why would that be useful? For example, you could write text as binary into your registry:

Md HKCU:\Software\Test
Set-ItemProperty HKCU:\Software\Test ProductName -Type Binary -Value ([Byte[]][Char[]]“MyProduct”)

Twitter This Tip! ReTweet this Tip!