PowerShell Summit 2017–agenda

We’re finalising the agenda for the 2017 Summit. Most of the sessions are now up on the event site. Go to https://powershell.org/summit/ and click the Brochure and Registration link. You’ll be able to down load a brochure describing next years Summit and view the proposed agenda (it is subject to change with no notice).

Registration opens 1 November 2016

Posted in Powershell, Summit | Leave a comment

Server Uptime

Its easy to get the last boot time of a Windows machine but how do you get the uptime

function Get-Uptime {
param (
   [string]$ComputerName = $env:COMPUTERNAME

$os = Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $ComputerName

$uptime = (Get-Date) – $os.LastBootUpTime



Use Get-CimInstance to get the Win32_OperatingSystem class. To calculate the uptime subtract the value of LastBootTime from the current time and date.

You’ll get a Timespan object returned.

PS> Get-Uptime

Days              : 1
Hours             : 10
Minutes           : 32
Seconds           : 26
Milliseconds      : 838
Ticks             : 1243468385381
TotalDays         : 1.4391995201169
TotalHours        : 34.5407884828056
TotalMinutes      : 2072.44730896833
TotalSeconds      : 124346.8385381
TotalMilliseconds : 124346838.5381

Pick out whichever properties you need for your report

Posted in PowerShell and CIM, PowerShell and WMI | 1 Comment

Current location

Windows 10 gives you the option of installing BASH on Ubuntu – https://msdn.microsoft.com/en-us/commandline/wsl/about also known as the Windows Subsystem for Linux (WSL). More information from https://blogs.msdn.microsoft.com/wsl/

I thought it would be interesting to compare some of the bash commands with their PowerShell equivalents.

First off – current location.

Its not obvious from the bash prompt where you are in the file system so you use pwd

root@RSsurfacePro2:~# pwd

In PowerShell you use Get-Location

PS> Get-Location


Interestingly you can use pwd in PowerShell

PS> pwd


That’s because pwd is an alias for Get-Location

PS> get-alias pwd | fl

DisplayName       : pwd -> Get-Location
CommandType       : Alias
Definition        : Get-Location
ReferencedCommand : Get-Location
ResolvedCommand   : Get-Location

If you want to discover all existing aliases for Get-Location

PS> get-alias | where ResolvedCommand -like ‘get-location’ | fl

DisplayName       : gl -> Get-Location
CommandType       : Alias
Definition        : Get-Location
ReferencedCommand : Get-Location
ResolvedCommand   : Get-Location

DisplayName       : pwd -> Get-Location
CommandType       : Alias
Definition        : Get-Location
ReferencedCommand : Get-Location
ResolvedCommand   : Get-Location

You’ll find that many core PowerShell cmdlets have aliases corresponding to Linux commands. Note that they are removed for PowerShell on Linux to avoid confusion.

Look out for other comparisons soon.

Posted in Bash, Powershell | Leave a comment

Easy and Expert

This is a very interesting article – https://powershell.org/2016/10/12/no-easy-button-for-configuration-management/.

The premise that there is no “easy” button in IT is spot on and fits with this quote from  Theodore Roosevelt:

“Nothing in the world is worth having or worth doing unless it means effort, pain, difficulty…”  

IT is constantly changing – new technologies, new techniques, and new ways of looking at the problems.

The only way to survive is to keep learning. If you don’t you become part of the problem.

One of the comments castigating the author of the for declaring themselves a “newbie” given the work they’d put into learning DSC also caught my eye. When does someone move from being a newbie to becoming competent or even an expert?

Its as much in the mind of your audience as anything. I’ve been using PowerShell since the days of the version 1 beta code and have written and spoken more about the subject than I care to remember. Does that make me an expert? Many people seem to think so but as far as I’m concerned I’m still learning. So is everyone else that I consider an expert. To misquote

“Expertise is in the eye of the beholder”

When things change or you move onto something new the newbie clock gets reset so we’re all really newbies. Another way to think about it is that an expert is a newbie that has been working with the technology just that little bit longer.

Be wary of self proclaimed experts. The true experts tend to just get on with it.

Posted in Opinion | Leave a comment

Filter early and WQL

What’s wrong with this:

Get-CimInstance -ClassName Win32_Service |
where {$_.State -eq ‘Running’ -and $_.StartName -notlike ‘LocalSystem’ -and $_.StartName -notlike ‘NT Authority*’} |
select PSComputerName, Name, DisplayName, State, StartName

Nothing except that its inefficient. if you ran this against a remote machine the filtering would happen on the local machine AFTER you’d dragged everything across the network. May not matter for a few machines but when you get to hundreds or thousands of machines it will have an impact

You need to use a filter. First try would be something like this:

Get-CimInstance -ClassName Win32_Service  -Filter “State = ‘Running’ AND StartName != ‘LocalSystem’ AND NOT StartName LIKE ‘NT Authority%'”|
select PSComputerName, Name, DisplayName, State, StartName

Unfortunately any services with a NULL StartName will also be filtered out

This will work

Get-CimInstance -ClassName Win32_Service  -Filter “State = ‘Running’ AND Startname != ‘LocalSystem’ AND StartName != ‘NT AUTHORITY\\LocalService’ AND StartName != ‘NT AUTHORITY\\NetworkService'”|
select PSComputerName, Name, DisplayName, State, StartName

Same results are obtained with Get-WmiObject

Posted in CIM, PowerShell and CIM, PowerShell and WMI | Leave a comment

Opportunities come and go

The deadline for the submission of proposals for the 2017 has passed. We are NOT taking any new submissions. if you’ve been in communication regarding a submission thats fine its still under consideration and I’ll be in touch.

On the positive side the call for speakers for the European PowerShell conference has opened – http://www.powertheshell.com/psconfeu/

Posted in Powershell | Leave a comment

PowerShell classes

I’ve just had an article on PowerShell classes published on the UK TechNet bog – https://blogs.technet.microsoft.com/uktechnet/2016/09/29/powershell-classes/

Posted in PowerShell v5 | Leave a comment