Monthly Archive

Categories

Monthly Archives: December 2017

PowerShell v6: #6 Windows compatibility

PowerShell v1 through v5.1 have been based on the full .NET framework. PowerShell v6 is based on .NET core which is a cross platform subset of .NET that’s available for Windows, Linux and mac. This has meant that Powershell v6 on Windows is a poor relation of PowerShell v5.1 in terms of the functionality available – for instance the Active Directory module won’t run on PowerShell v6. This makes v6 a backward step for administering Windows. Steps are being taken that will improve Windows compatibility of PowerShell v6.

 

The .NET core team are releasing a Windows compatibility pack – see https://blogs.msdn.microsoft.com/dotnet/2017/11/16/announcing-the-windows-compatibility-pack-for-net-core/ for what’s likely to be in it.

A number of cmdlets including:

WMI cmdlets

Eventlog cmdlets

PerCounter cmdlets

 

are ear marked for being ported to PowerShell v6 using the compatibility pack. When this happens and what else is will be included is unsure. You can follow the issue at https://github.com/PowerShell/PowerShell/issues/5603

Hyper-V VM start time

Its fairly easy to see how long a VM has been running – but how do you know the Hyper-V VM start time?

In Hyper-V the VM uptime is easy to find

PS> Get-VM | where State -eq 'Running'

Name       State   CPUUsage(%) MemoryAssigned(M) Uptime           Status             Version 
 ----       -----   ----------- ----------------- ------           ------             ------- 
 W16AS01    Running 6           1246              00:12:18.6480000 Operating normally 8.0 
 W16CN01    Running 0           538               00:09:18.2180000 Operating normally 8.2 
 W16DC01    Running 0           940               00:15:19.1550000 Operating normally 8.0 
 W17035CN01 Running 0           540               00:06:17.7980000 Operating normally 8.2 
 W1709CN01  Running 0           512               00:03:15.8540000 Operating normally 8.2

 

Sometimes you might want to know when the VM was started

The Uptime property is a TimeSpan so you can calculate the start time

PS> $now = Get-Date 
PS> Get-VM | where State -eq 'Running' | select Name, @{N='StartTime'; E={$now - $_.Uptime}}

Name       StartTime 
 ----       --------- 
 W16AS01    02/12/2017 10:23:15 
 W16CN01    02/12/2017 10:26:16 
 W16DC01    02/12/2017 10:20:15 
 W17035CN01 02/12/2017 10:29:16 
 W1709CN01  02/12/2017 10:32:18

 

Once you’ve added the calculated property you can use like any other property

PS> Get-VM | where State -eq 'Running' | select Name, @{N='StartTime'; E={$now - $_.Uptime}} | sort StartTime

Name       StartTime 
----       --------- 
 W16DC01    02/12/2017 10:18:46 
 W16AS01    02/12/2017 10:21:47 
 W16CN01    02/12/2017 10:24:47 
 W17035CN01 02/12/2017 10:27:48 
 W1709CN01  02/12/2017 10:30:50

 

Using calculated fields like this is a handy technique for changing the way data is displayed.