PowerShell Summit Europe 2015–nearly sold out

There are a handful of places left for the PowerShell Summit Europe 2015. If you want to secure a place I recommend that you book very soon as we can’t extend capacity any further.
Playing with the range operator

The range operator allows you to reference a range of numbers
1..10
is equivalent to
1,2,3,4,5,6,7,8,9,10
If you want anything other than numbers you’re stuck as the range operator only works with integers
though you can have a decrementing list
10..1
65..74 | foreach {[char]$psitem}
would be A – J
If you want A-Z
65..90 | foreach {[char]$psitem}
For lowercase letters (a – z) use
97..122 | foreach {[char]$psitem}
You can even work from an array of values
$data = ‘value1′,’value2′,’value3′,’value4′,’value5′,’value6′,’value7′,’value8′,’value9′,’value10’
$data[3..6]
$data[6..3]
PowerShell DSC for Linux

PowerShell DSC for Linux has moved out of CTP and v1 is available for download from http://www.microsoft.com/en-us/download/details.aspx?id=46919
You will find more details at http://blogs.msdn.com/b/powershell/archive/2015/05/06/powershell-dsc-for-linux-is-now-available.aspx
You will need to download OMI version 1.0.8-1 which is available from https://collaboration.opengroup.org/omi/documents.php?action=show&dcat=&gdid=32721
OMI has to be installed on the Linux box before the DSC package
A useful getting started guide is available https://technet.microsoft.com/en-us/library/mt126211.aspx
I demonstrated DSC for Linux at the recent PowerShell Summit NA 2015
https://www.youtube.com/watch?v=X5igUenOJiU&index=30&list=PLfeA8kIs7CochwcgX9zOWxh4IL3GoG05P
though things have changed a bit since I built that demo environment using the DSC for Linux CTP. I’m going to rebuild my Linux box with the new bits and give it a whirl.
Being able to manage Windows and Linux environments through the same techniques, and in some cases the same DSC configurations is a big step forward
WMF 5.0 April 2015 preview – – software inventory logging

A software inventory module is now included with the April 2015 WMF 5.0 preview
£> Get-Command -Module SoftwareInventoryLogging | select Name
Name
—-
Get-SilComputer
Get-SilComputerIdentity
Get-SilData
Get-SilLogging
Get-SilSoftware
Get-SilUalAccess
Get-SilWindowsUpdate
Publish-SilData
Set-SilLogging
Start-SilLogging
Stop-SilLogging
Windows updates are always a good place to start poking into your systems
£> Get-Command Get-SilWindowsUpdate -Syntax
Get-SilWindowsUpdate [[-ID] <string[]>] [-CimSession <CimSession[]>]
[-ThrottleLimit <int>] [-AsJob] [<CommonParameters>]
£> Get-SilWindowsUpdate
ID : KB3055381
InstallDate : 4/30/2015
etc
The parameters for Get-SilWindowsUpdate look like those I’d expect from a CDXML module. Inspection of C:\Windows\System32\WindowsPowerShell\v1.0\modules\SoftwareInventoryLogging\
shows a number of cdxml files
MsftSil_Computer.cdxml
MsftSil_ComputerIdentity.cdxml
MsftSil_Data.cdxml
MsftSil_ManagementTasks.psm1
MsftSil_Software.cdxml
MsftSil_UalAccess.cdxml
MsftSil_WindowsUpdate.cdxml
Msft_MiStreamTasks.cdxml
The WMF 5,0 release notes supply a link to further data of software inventory logging – interestingly its flagged as a Windows Server 2012 R2 page.
Trying the cmdlet against a Windows Server 2012 R2 system running WMF 4.0 (with the November 2014 roll up)
$cs = New-CimSession -ComputerName W12R2SUS
Get-SilWindowsUpdate -CimSession $cs
£> Get-SilWindowsUpdate -CimSession $cs
ID : KB3006193
InstallDate : 1/5/2015
PSComputerName : W12R2SUS
etc
This means the class is on our Windows Server 2012 R2 box so we could use it directly
£> Get-CimInstance -Namespace root/InventoryLogging -ClassName MsftSil_WindowsUpdate | Format-Table -a
ID InstallDate PSComputerName
— ———– ————–
KB3006193 1/5/2015 12:00:00 AM
KB2894856 9/14/2014 12:00:00 AM
etc
This module supplies a useful way to find out the software installed on our systems – I’ll be digging into this over a few more posts
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
WMF 5.0 – Clipboard cmdlets

The April 2015 WMF 5.0 preview brings new functionality in the shape of cmdlets for working directly with the clipboard.
You use Set-Clipboard to put data onto the clipboard
£> get-command Set-Clipboard -Syntax
Set-Clipboard [-Append] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-Clipboard [-Value] <string[]> [-Append] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-Clipboard -Path <string[]> [-Append] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-Clipboard -LiteralPath <string[]> [-Append] [-WhatIf] [-Confirm] [<CommonParameters>]
You can add text or files to the clipboard. Notice that you can use –Append to add to the clipboard content rather than overwriting any existing data.
For instance:
Set-Clipboard -Value “test”
The contents of the clipboard are retrieved using Get-Clipboard
£> Get-Clipboard -Raw
test
As well as raw data you can pull data in a number of formats.
£> Get-Command Get-Clipboard -Syntax
Get-Clipboard [-Format <ClipboardFormat>] [-TextFormatType <TextDataFormat>] [-Raw] [<CommonParameters>]
Format can be one of: Text, FileDropList, Image, Audio
TextFormat type can be one of: Text, UnicodeText, Rtf, Html, CommaSeparatedValue
These all produce the same result:
£> Get-Clipboard -Raw
test
£> Get-Clipboard -TextFormatType Text
£> Get-Clipboard -Raw
test
£> Get-Clipboard -Format Text
£> Get-Clipboard -Raw
test
Notice how use the TextFormatType Text or Format Text cause get-Clipboard to be called again with the –Raw parameter
One obvious and useful tasking for the clipboard cmdlets is copying commands between PowerShell sessions:
On the source machine
£> Get-History -Id 43
Id CommandLine
— ———–
43 Find-Package -Name PSReadline -Source PSGallery | fl *
Set-Clipboard -Value (Get-History -Id 43 | select -ExpandProperty Commandline)
On the target machine:
Invoke-Expression -Command (Get-Clipboard -Raw)
This is one set of cmdlets that will generate many more uses as you experiment with them
WMF 5.0–New-TemporaryFile

Creating a temporary file in PowerShell 4.0 and earlier has been possible using a number of techniques such as:
£> $file = [System.IO.Path]::GetTempFileName()
£> $file
C:\Users\Richard\AppData\Local\Temp\tmpEFAD.tmp
With the April 2015 WMF 5.0 preview this becomes much easier
£> $file2 = New-TemporaryFile
£> $file2
Directory: C:\Users\Richard\AppData\Local\Temp
Mode LastWriteTime Length Name
—- ————- —— —-
-a—- 4/30/2015 12:42 PM 0 tmp1FE1.tmp
Now you can create files simply and easily without having to remember the .NET syntax.
Notice that the temporary files are automatically created in your TEMP folder.
£> $env:TEMP
C:\Users\Richard\AppData\Local\Temp
WMF 5.0 April 2015 Preview is available

The PowerShell team have released the April 2015 WMF 5.0 preview. Details from http://blogs.msdn.com/b/powershell/archive/2015/04/29/windows-management-framework-5-0-preview-april-2015-is-now-available.aspx
Blocksize missing?

I recently had a question asking why the Bloacksize property on Win32_LogicalDisk is empty but is populated on Win32_Volume.
The thing is to remember the underlying thing that these 2 CIM classes represent.
A logical disk is a subdivision of an extended partition. An extended partition can hold one or more logical disks.
When you create a volume on a disk you use either a primary partition or a logical disk from an extended partition. Until you format the volume you can’t have a block size as that is determined by the parameters you use to perform the format.
The documentation for Win32_LogicalDisk states that block size is not populated for logical disks https://msdn.microsoft.com/en-us/library/aa394173(v=vs.85).aspx.