Left-Padding a String

I’ll be honest; .NET has more methods and classes and properties than I can shake an idiom at. In my previous blog post, I needed to left-pad a string with zeroes in order to treat it as a 32-bit binary value to [Array]::Reverse(). I also had to do the same for an 8-bit value, but…

5

One-Liner: Left-Padding a String with Zeroes

Yesterday’s post had a little bit of sleight-of-hand involved.  For the IPv4 address to UInt64 conversion to work, each octet had to be converted into an 8-character string of ones and zeroes.  However, [convert]::ToString($int, 2) doesn’t zero pad, and this is now a string, not an Int, so I can’t use .Net’s ToString() formatting line…

0

Regular Expressions, Search-and-Replace Interpolation and Delegates

This (and the previous post) stem from me stumbling onto this page: http://stackoverflow.com/questions/17229866/powershell-hex-to-string-conversion/19151495 Last time, we looked at hex-decoding a string. In the above, the original poster had file of space-delimited lines, each with three fields: the username, the user’s domain, and the hex-encoded password. The requested solution was to only hex-decode only the third…

0

Splitting a Hex-Encoded String into Pairs of Hex Characters (a.k.a. To Pull a Noah)

Simple enough task: I have a hex-encoded string and need to decode it.  Now, we all know that to encode a string to hex is to cast each [char] to [int], then shove it through the "{0:X}" format specifier, then concatenate all the strings. $string = "The quick brown dog"; [string]::Join($null, ([char[]]$string | % {…

1

PowerShell for Non-N00bs: Formatting Time With RegEx

So, last episode we learned how to format the output of a LastBootUpTime property from the WIN32_OperatingSystem WMI query to something human readable using WMI.  What if that didn’t exist?   PSH> (Get-WmiObject -Query ‘SELECT LastBootUpTime FROM Win32_OperatingSystem’).LastBootUpTime20090712112652.125000-420 So, we have this ugly string.  Hhow do we convert it to something we can use (namely, a string…

0

PowerShell for Non-N00bs: How Much is That Character in the Window? (Or, How to Change Your Password Without Really Trying)

I’m creating a slightly different track here.  PowerShell for Non-N00bs is for me to track some of the tidbits I’ve found along the way. This will be a two-fer article.  By this I mean I’m going to address two tangentially related subjects: how to find an ‘odd’ character that is visible, but not matching a…

2