PowerShell for Windows Admins

September 29, 2014  8:39 AM

PowerShell Summit Europe 2014–Monday afternoon

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Mike Pfeiffer started the Monday afternoon session with a demonstration of using PowerShell to manage Amazon Web Services.

Dan Harman, from the PowerShell team, followed with PowerShell Repositories Unleashed. Oneget is a software package manager

Oneget has PowerShell cmdlets; a C# API and a WMI provider may follow. Originally released against a Chocolately provider – others will follow.  Dan showed a nuget provider being installed

PowerShellGet is overlays OneGet and provides the ability t0 install and manage PowerShell modules

Package providers aren’t trusted by default. You can configure repositories to be trusetd – especially useful if you create your own

The third session of the afternoon was supplied by Tobias Weltner on Sophisticated Techniques of Plain Text Parsing.

PowerShell is based on text but often need to work with unstructured text data.  He started with using –split and lead into using regular expressions.

Can force into CSV format by supplying headers

Experience based learning enables more sophisticated processing

Select-string can also be used to parse textual data.

The final Monday session was Do custom objects dream about ETS? by  Bartosz Bielawski

Bartek showed how to create custom objects and set its type.  Once you have that done you can create formatting and type data to control how the data is displayed.

September 29, 2014  5:15 AM

PowerShell Summit Europe 2014–Monday morrning

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The Summit started with a walk through the Monad Manifesto by Jeffrey Snover. This covered the history of PowerShell, where it came from, why it came about and the features introduced with the subsequent versions.

A few highlights:

  • DSC is a huge area and will expand
  • ISE will be able to edit files on remote machines
  • DSC resource kit now at wave 7 and more are in the pipeline
  • Classes can be created in PowerShell

The futures section included the intriguing possibility that eventually there may be an open source version of PowerShell.  Please note this is a possibility not a guarantee.

Second up was Steve Murawski talking about the creation of DSC resources ahead of our evening DSC resource hackathon.

Steve showed the structure of a resource and some of the gotchas such as versioning and the need to match parameter sets across the get/test/set-resource functions.

Infrastructure as code – ignore individual machines. Destroy & rebuild if there are problems

Final session of the morning was Jeff Wouters speaking on Speedy PowerShell

After explaining the pipeline Jeff started showed the impact of filtering on performance including how the new where and for each syntax introduced in PowerShell v4 works.

He also covered how loops and workflows can impact performance

September 28, 2014  3:43 PM

And the Summit begins

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The PowerShell Summit Europe 2014 began unofficially this evening with an informal gathering for drinks and conversation – no prizes for guessing the main topic of conversation!!

One of the greatest things about these Summits is the ability to talk to other people about what they are doing with PowerShell and to discover new ways to do things and new things to do with PowerShell.

The conversations continued over dinner and will no doubt continue through the next 3 days.

September 23, 2014  2:01 PM

PowerShell Summit Europe 2014 – final agenda

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The final agenda for the PowerShell Summit is available at http://eventmgr.azurewebsites.net/event/home/PSEU14

Circumstances beyond the control of PowerShell.org have meant we’ve had to make a few changes to the agenda from that previously published

September 22, 2014  2:26 PM

WMI and CIM dates

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

A question on the forum asked about extracting the year from the ReleaseDate property returned by Win32_BIOS

They were trying to do this:

Get-CimInstance Win32_BIOS | Select-Object @{n=”ReleaseDate”;e={$_.ConvertToDateTime($_.ReleaseDate).year()}}

There are 2 problems with this approach – firstly the objects that Get-CimInstance produces don’t have the ConvertToDateTime method (its added by PowerShell to the objects produces by Get-WmiObject) and secondly on a DateTime object Year is a property not a method.

If you use the WMI cmdlet you see this

£> Get-WmiObject -Class Win32_Bios | select Releasedate


The date is in WMI format and needs to be converted.

£> Get-WmiObject Win32_BIOS | Select-Object @{n=”ReleaseDate”;e={$_.ConvertToDateTime($_.ReleaseDate)}}

12/05/2014 01:00:00

If you want just the year

£> Get-WmiObject Win32_BIOS | Select-Object @{n=”ReleaseDate”;e={($_.ConvertToDateTime($_.ReleaseDate)).Year}}


This conversion is already done for you with the CIM cmdlets

£> Get-CimInstance -CimSession $c -ClassName Win32_Bios | select ReleaseDate

12/05/2014 01:00:00

Again if you just want the year

£> ((Get-CimInstance -CimSession $c -ClassName Win32_Bios).ReleaseDate).Year

September 20, 2014  10:13 AM

Creating a DHCP reservation

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
DHCP Reservation, Powershell

For my demo at the PowerShell Summit I wanted to use DHCP for the Linux machine but guarantee that it had a specific IP address. Time to create a DHCP reservation

The DHCP module in Windows Server 2012 and 2012 R2 enables you to create a reservation:

Add-DhcpServerv4Reservation -ScopeId -IPAddress -ClientId 00155D36C906 -Description “Linux machine” -Name “SphinxLX01”

The clientid is the VMs MAC address.

You can view the current reservations:

£> Get-DhcpServerv4Reservation -ScopeId | fl *
IPAddress             :
ScopeId               :
AddressState          : ActiveReservation
ClientId              : 00-15-5d-36-c9-06
Description           : LInux machine
Name                  : SphinxLX01
Type                  : Both

You can view current leases:

£> Get-DhcpServerv4Lease -ScopeId | fl *
IPAddress             :
ScopeId               :
AddressState          : ActiveReservation
ClientId              : 00-15-5d-36-c9-06
ClientType            : Dhcp
Description           : LInux machine
DnsRegistration       : NotApplicable
DnsRR                 : NoRegistration
HostName              : SphinxLX01
LeaseExpiryTime       :
NapCapable            : False
NapStatus             : FullAccess
PolicyName            :
ProbationEnds         :
ServerIP              :

And all from the comfort of your very own PowerShell prompt.

September 17, 2014  12:48 PM

Getting the most from your PowerShell Summit

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

With the first European PowerShell Summit rapidly approaching – 11 days and counting – I thought I’d give you a few ideas on how to get the maximum out of the Summit.

First – ask questions – lots of questions.  The speakers are masters of their topics and if you need to drill deeper to understand something talk to them in the breaks or over lunch. At Summits in North America we’ve had discussions go on well into the early morning!

Don’t try and copy code that you see.  The demo code and slides will be available after the Summit.

All of the sessions are recorded so you will have a chance to replay bits you need to see again. Some of the speakers will cram a lot into the sessions so accessing the recordings will be useful

Talk to your fellow attendees – I seen discussions where one persons problem was solved by another attendee who’d gone through the same issues

Make suggestions for topics you’d like covered at future Summits – if we get enough demand for a topic we’ll find a speaker

Representatives of the PowerShell will be present, and speaking. Talk to them. Tell them what you like. More importantly tell them what you don’t like or what isn’t working for you.  They love feed back from real users.

A number of PowerShell MVPs will be speaking or in the audience. This is your opportunity to talk to them and  ask your difficult questions. They are recognised experts and will be more than willing to help.

Lastly – ask questions. Lots of questions. If you can’t get your questions answered at a PowerShell Summit – there is a serious problem.

September 14, 2014  4:58 AM

Output from jobs

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I tripped over a little problem the other day that’s worth reporting. I was running something like this:

$sb = {
$procs = get-service
$procs | Export-Csv test.csv -NoTypeInformation

Start-Job -ScriptBlock $sb -Name test

I was collecting some data and outputting a CSV. My problem was more complex but this stands as a good example.

I didn’t get the data I wanted

Thinking about it I put the full path to where I wanted the CSV

$sb = {
$procs = get-service
$procs | Export-Csv C:\MyData\scripts\Test\test.csv -NoTypeInformation

Start-Job -ScriptBlock $sb -Name test

And it works.

So where did my data go in the original version?

I ran this:

$sb = {

$procs = get-service
$procs | Export-Csv test.csv -NoTypeInformation

Start-Job -ScriptBlock $sb -Name test

And then pulled the data from the job

£> Receive-Job -Id 10


Obvious really – a job runs in a new Powershell process that doesn’t run your profile so it starts in the default location  – which is your home directory. And sure enough the CSV file is there

£> ls C:\Users\Richard\Documents\*.csv
Directory: C:\Users\Richard\Documents
Mode                LastWriteTime     Length Name
—-                ————-     —— —-
-a—        14/09/2014     11:50      46042 test.csv

I can’t remember how many times I’ve told people that PowerShell jobs run in a separate process so I should have realized.  Excellent example of the more you know the more you need to learn

September 12, 2014  10:49 AM

Multiple triggers on a scheduled task

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Setting up a scheduled task can be accomplished like this:

$taskname = ‘Test Job’

Get-ScheduledTask -TaskName $taskname -ErrorAction SilentlyContinue |  Unregister-ScheduledTask -Confirm:$false

$trigger = New-ScheduledTaskTrigger -Daily -At 03:00

$actionscript = ‘-NoExit -NonInteractive -NoProfile -WindowStyle Normal -NoLogo -Command “&{get-process}”‘

$pstart =  “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”

$action = New-ScheduledTaskAction -Execute $pstart -Argument $actionscript
Register-ScheduledTask -TaskName $taskname -Action $action -Trigger $trigger -RunLevel Highest -Description “Test job”

Define the task name and then unregister (remove) any instances of that task

You then define the trigger and actions and finally register the task with the name you defined earlier.

The script above will create a task to run at 3am.

You can force the task to run as a test:

Start-ScheduledTask -TaskName ‘Test Job’

But what about if you want to run the task multiple times during the day. Simple. You define multiple triggers:

$taskname = ‘Test Job’

Get-ScheduledTask -TaskName $taskname -ErrorAction SilentlyContinue |  Unregister-ScheduledTask -Confirm:$false

$triggers = @()
$triggers += New-ScheduledTaskTrigger -Daily -At 03:00
$triggers += New-ScheduledTaskTrigger -Daily -At 09:00
$triggers += New-ScheduledTaskTrigger -Daily -At 15:00
$triggers += New-ScheduledTaskTrigger -Daily -At 21:00

$actionscript = ‘-NoExit -NonInteractive -NoProfile -WindowStyle Normal -NoLogo -Command “&{get-process}”‘

$pstart =  “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”

$action = New-ScheduledTaskAction -Execute $pstart -Argument $actionscript
Register-ScheduledTask -TaskName $taskname -Action $action -Trigger $triggers -RunLevel Highest -Description “Test job”

Define an array and then add the triggers into it. Remember to use the array when you register the task.

You can test the triggers on a scheduled task:

Get-ScheduledTask -TaskName ‘Test Job’ | select -ExpandProperty Triggers

September 10, 2014  2:07 PM

OneNote and XML–finding pages

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
office 2013, Powershell

Pages are towards the bottom of the hierarchy in OneNote – though we still haven’t dived into the content of pages yet.

You can find the pages in your notebooks like this:

$onenote = New-Object -ComObject OneNote.Application
$scope = [Microsoft.Office.Interop.OneNote.HierarchyScope]::hsPages
[ref]$xml = ”

$onenote.GetHierarchy($null, $scope, $xml)

$schema = @{one=”http://schemas.microsoft.com/office/onenote/2013/onenote”}

$xpath = “//one:Notebook/one:Section”
Select-Xml -Xml (

$xml.Value) -Namespace $schema -XPath $xpath |
foreach {

There’s one drawback to this – all you get is the page names:
PowerShell Summit
Personal information
Book Series
Infrastructure Architecture
PS Deep Dive
Deep Dive US12

You need to play around with Xpath a bit more to get a meaningful structure – ideally notebook – section – page

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: