Monthly Archive

Categories

Monthly Archives: May 2015

WMF 5.0 April 2015 preview – – creating guid

Creating a GUID has always been possible with PowerShell – you just had to drop into .NET

 

£> [System.Guid]::NewGuid()

Guid
----
46c130ca-39ff-463c-b7fb-ed728a1c134f

 

With the latest WMF 5.0 preview life gets easier:

£> Get-Command New-Guid -Syntax

New-Guid [<CommonParameters>]

 

£> New-Guid

Guid
----
112866a5-1662-4265-b851-f9086607bcb2

 

The New-Guid cmdlet happily creates a GUID for you – and you don’t have to remember the >NET syntax.

 

If you want the GUID in a variable as a string

£> $guid = New-Guid | select -ExpandProperty Guid
£> $guid
5c832d40-0ea4-4b42-b0bd-b228da008c9d

WMF 5.0 April 2015 preview – – Format-Hex

Have you ever needed to generate a hex representation of a string or binary data?

Say you have a string - 'PowerShell Rocks'

 

And you want to go the hex representation which is

50 6f 77 65 72 53 68 65 6c 6c 20 52 6f 63 6b 73

 

You would have to do something like this

$hexary = @()
$chars = 'PowerShell Rocks' -split ''

foreach ($char in $chars) {
if ($char -ne '') {
   $hexary += [convert]::ToString(([byte][char]$char),16)
}
}

$hexary -join ' '

 

Split the string into an array of strings each of a single character. If the string is not empty convert it to a [char] then a [byte] and finally a string formatted as hex.

 

The April 2015 WMF 5.0 preview simplifies that process

£> 'PowerShell Rocks' | Format-Hex

                   00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000   50 6F 77 65 72 53 68 65 6C 6C 20 52 6F 63 6B 73  PowerShell Rocks

 

You can also view binary files such as Word documents in .doc format