Monthly Archive

Categories

Monthly Archives: April 2015

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>]

 

For instance:

Set-Clipboard -Value "test"

 

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.

 

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.

OMI/CIM/WMI dictionary

Don Jones provides a very good summary of the similarities and differences between WMI, CIM and OMI http://powershell.org/wp/2015/04/24/management-information-the-omicimwmimidmtf-dictionary/

Recommended reading if you’re using these technologies

PowerShell Summit NA 2015

We’re into the last afternoon as I write this. We’ve had some amazing sessions with excellent presentations on DSC, security aspects of using PowerShell, using and manipulating data with PowerShell, PowerShellGet, Nano server, working with ACLs in PowerShell and PowerShell help.

 

This has been out third Summit and North America and probably the best. We’ve had a great audience and are planning hard for next year

PowerShell Summit NA 2015–announcements

The PowerShell Team announced some things on Monday

OneGet is now PowerShell Package Maanger

 

Next WMF 5.0 preview will become available on 30 April

 

Pester – the testing module – will be included in Windows

 

Open Source projects on Github:

DSC Resource Kit

PowerShell Script Analayzer

Virtual Studio PowerShell Plug-in

PowerShell Summit NA 2015–recordings

The recordings from PowerShell Summit NA 2015 are starting to become available on the powershell.org you tube channel.

This gives you an opportunity to watch the sessions you missed.

If you didn’t attend the Summit it gives you the opportunity to see what the Summit is like and why you should be there

PowerShell Summit NA 2015–Day 1

The third PowerShell Summit kicked off Monday 20 April with breakfast and a welcome from Don Jones and the powershell.org board.

 

The PowerShell Summit is the premier PowerShell event in the world with 3 days of  in depth PowerShell sessions delivered by the PowerShell Team, PowerShell MVPs and other acknowledged  PowerShell experts.

 

The attendees are extremely knowledgeable asking probing questions to keep the speakers on their toes.

 

DSC is a major theme with the opening sessions covering this topic -  Don Jones on resource design and Jason Helmick on using DSC to deploy IIS and PWA.

Other sessions included using DSC with Active Directory, and PowerShell for the reluctant DBA.

 

More esoteric topics included a look at PowerShell and Odata & Monitoring with PowerShell.

 

The day closed with the 140 attendees listening to Jeffrey Snover discussing the State of PowerShell – where its come from and where its going

PowerShell Summit NA 2015 speakers

Want to learn a bit more about some of the speakers at the PowerShell Summit?  Head over to the Scripting Guy blog - http://blogs.technet.com/b/heyscriptingguy/ – to see a series of posts giving you some background, and pictures, of a number of speakers.