Chaining Type Conversions

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!


Posted Sep 09 2010, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.