Sunday, June 8, 2014

First look at Powershell 5.0

Last time I wrote on this blog, Powershell 4 was king and it boasted more than 1300 cmdlets on its Windows 2012 R2 platform:
PS C:\Users\carlo> Get-Command| measure

Count    : 1301
Average  :
Sum      :
Maximum  :
Minimum  :
Property :
There were more than 60 modules, covering most of the aspects of a server configuration:
Get-Module -ListAvailable

    Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version    Name                                ExportedCommands                                             
---------- -------    ----                                ----------------                                             
Manifest    AppLocker                           {Get-AppLockerFileInformation, Get-Ap
Manifest    Appx                                {Add-AppxPackage, Get-AppxPackage, Ge
Manifest   1.0        BestPractices                       {Get-BpaModel, Get-BpaResult, Invoke-
Manifest    BitsTransfer                        {Add-BitsFile, Complete-BitsTransfer,
Manifest    BranchCache                         {Add-BCDataCacheExtension, Clear-BCCa
Manifest    CimCmdlets                          {Get-CimAssociatedInstance, Get-CimCl
Manifest    DirectAccessClientComponents        {Disable-DAManualEntryPointSelection,
Script     3.0        Dism                                {Add-AppxProvisionedPackage, Add-Wind
Manifest    DnsClient                           {Resolve-DnsName, Clear-DnsClientCach
Manifest    International                       {Get-WinDefaultInputMethodOverride, S
Manifest    iSCSI                               {Get-IscsiTargetPortal, New-IscsiTarg
Manifest    IscsiTarget                         {Add-ClusteriSCSITargetServerRole, Ad
Script    ISE                                 {New-IseSnippet, Import-IseSnippet, G
Manifest    Kds                                 {Add-KdsRootKey, Get-KdsRootKey, Test
Manifest    Microsoft.PowerShell.Diagnostics    {Get-WinEvent, Get-Counter, Import-Co
Manifest    Microsoft.PowerShell.Host           {Start-Transcript, Stop-Transcript}
Manifest    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-It
Manifest    Microsoft.PowerShell.Security       {Get-Acl, Set-Acl, Get-PfxCertificate
Manifest    Microsoft.PowerShell.Utility        {Format-List, Format-Custom, Format-T
Manifest    Microsoft.WSMan.Management          {Disable-WSManCredSSP, Enable-WSManCr
Manifest   1.0        MMAgent                             {Disable-MMAgent, Enable-MMAgent, Set
Manifest    MsDtc                               {New-DtcDiagnosticTransaction, Comple
Manifest    NetAdapter                          {Disable-NetAdapter, Disable-NetAdapt
Manifest    NetConnection                       {Get-NetConnectionProfile, Set-NetCon
Manifest    NetEventPacketCapture               {New-NetEventSession, Remove-NetEvent
Manifest    NetLbfo                             {Add-NetLbfoTeamMember, Add-NetLbfoTe
Manifest    NetNat                              {Get-NetNat, Get-NetNatExternalAddres
Manifest    NetQos                              {Get-NetQosPolicy, Set-NetQosPolicy, 
Manifest    NetSecurity                         {Get-DAPolicyChange, New-NetIPsecAuth
Manifest    NetSwitchTeam                       {New-NetSwitchTeam, Remove-NetSwitchT
Manifest    NetTCPIP                            {Get-NetIPAddress, Get-NetIPInterface
Manifest    NetworkConnectivityStatus           {Get-DAConnectionStatus, Get-NCSIPoli
Manifest    NetworkTransition                   {Add-NetIPHttpsCertBinding, Disable-N
Manifest   1.0        NFS                                 {Get-NfsMappedIdentity, Get-NfsNetgro
Manifest    PcsvDevice                          {Get-PcsvDevice, Start-PcsvDevice, St
Manifest    PKI                                 {Add-CertificateEnrollmentPolicyServe
Manifest   1.1        PrintManagement                     {Add-Printer, Add-PrinterDriver, Add-
Binary     1.0        PSDesiredStateConfiguration         {Set-DscLocalConfigurationManager, St
Script    PSDiagnostics                       {Disable-PSTrace, Disable-PSWSManComb
Binary    PSScheduledJob                      {New-JobTrigger, Add-JobTrigger, Remo
Manifest    PSWorkflow                          {New-PSWorkflowExecutionOption, New-P
Manifest    PSWorkflowUtility                   Invoke-AsWorkflow
Manifest    RemoteDesktop                       {Get-RDCertificate, Set-RDCertificate
Manifest    ScheduledTasks                      {Get-ScheduledTask, Set-ScheduledTask
Manifest    SecureBoot                          {Confirm-SecureBootUEFI, Set-SecureBo
Script    ServerCore                          {Get-DisplayResolution, Set-DisplayRe
Script    ServerManager                       {Get-WindowsFeature, Install-WindowsF
Cim    ServerManagerTasks                  {Get-SMCounterSample, Get-SMPerforman
Manifest    SmbShare                            {Get-SmbShare, Remove-SmbShare, Set-S
Manifest    SmbWitness                          {Get-SmbWitnessClient, Move-SmbWitnes
Manifest    SoftwareInventoryLogging            {Get-SilComputer, Get-SilSoftware, Ge
Manifest    StartScreen                         {Export-StartLayout, Import-StartLayo
Manifest    Storage                             {Add-InitiatorIdToMaskingSet, Add-Par
Manifest    TLS                                 {New-TlsSessionTicketKey, Enable-TlsS
Manifest    TroubleshootingPack                 {Get-TroubleshootingPack, Invoke-Trou
Manifest    TrustedPlatformModule               {Get-Tpm, Initialize-Tpm, Clear-Tpm, 
Manifest    UserAccessLogging                   {Enable-Ual, Disable-Ual, Get-Ual, Ge
Manifest    VpnClient                           {Add-VpnConnection, Set-VpnConnection
Manifest    Wdac                                {Get-OdbcDriver, Set-OdbcDriver, Get-
Manifest    Whea                                {Get-WheaMemoryPolicy, Set-WheaMemory
Manifest    WindowsDeveloperLicense             {Get-WindowsDeveloperLicense, Show-Wi
Script     1.0        WindowsErrorReporting               {Enable-WindowsErrorReporting, Disabl
Manifest    WindowsSearch                       {Get-WindowsSearchSetting, Set-Window
Starting from last May, Microsoft has published a preview release of the fifth version of its Management Framework (which corresponds to KB2894868), which includes Windows PowerShell 5 and brings updates to Desired State Configuration (DSC) as well as three new modules: OneGet, PowerShellGet, and NetworkSwitch.

The Microsoft download page gives you the possibility to download the framework for X86 and x64 computers. Each download is around 5 MBs:
For now these updates install only on Windows 8.1 or Windows 2012 R2, as stated in the release notes.

The MSU to use for Windows 2012 R2 is named WindowsBlue-KB2894868-x64.

Before the installation of the WMF 5.0, note that Windows 2012 R2 comes with the following versions of its components out-of-the-box:
PS C:\Users\carlo> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
CLRVersion                     4.0.30319.34014
BuildVersion                   6.3.9600.16394
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2
Let's go through the easy upgrade process to Powershell 5.0:
Start the installer...

Wait for it...
After the installation completes, a restart is required to apply the system changes.

Then when Powershell starts, you can see that you have moved to version 5 just looking at the date as it appears in the logo: if it shows 2014 then you have Powershell 5.0. If it shows 2013 then you have Powershell 4.0.
Also the output of $PSVersionTable shows us new values:
PS C:\Users\carlo> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.0.9740.0
WSManStackVersion              3.0
CLRVersion                     4.0.30319.34014
BuildVersion                   6.3.9740.0
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.2
With Powershell 5.0 some new cmdlets appear straight away:
PS C:\Users\carlo> Get-Command | measure

Count    : 1331
Average  :
Sum      :
Maximum  :
Minimum  :
Property :
Beside a refresh of Desired State Configuration (DSC) (you can read the complete post by Ravikanth Chaganti on PowershellMagazine), there are 30 new cmdlets, included in three new modules: OneGet, PowershellGet and NetworkSwitch:
PS C:\Users\carlo> gcm -Module NetworkSwitch

CommandType     Name                                               Source
-----------     ----                                               ------
Function        Disable-NetworkSwitchEthernetPort                  NetworkSwitch
Function        Disable-NetworkSwitchFeature                       NetworkSwitch
Function        Disable-NetworkSwitchVlan                          NetworkSwitch
Function        Enable-NetworkSwitchEthernetPort                   NetworkSwitch
Function        Enable-NetworkSwitchFeature                        NetworkSwitch
Function        Enable-NetworkSwitchVlan                           NetworkSwitch
Function        Get-NetworkSwitchEthernetPort                      NetworkSwitch
Function        Get-NetworkSwitchFeature                           NetworkSwitch
Function        Get-NetworkSwitchGlobalData                        NetworkSwitch
Function        Get-NetworkSwitchVlan                              NetworkSwitch
Function        New-NetworkSwitchVlan                              NetworkSwitch
Function        Remove-NetworkSwitchEthernetPortIPAddress          NetworkSwitch
Function        Remove-NetworkSwitchVlan                           NetworkSwitch
Function        Restore-NetworkSwitchConfiguration                 NetworkSwitch
Function        Save-NetworkSwitchConfiguration                    NetworkSwitch
Function        Set-NetworkSwitchEthernetPortIPAddress             NetworkSwitch
Function        Set-NetworkSwitchPortMode                          NetworkSwitch
Function        Set-NetworkSwitchPortProperty                      NetworkSwitch
Function        Set-NetworkSwitchVlanProperty                      NetworkSwitch

PS C:\Users\carlo> gcm -Module OneGet

CommandType     Name                                               Source
-----------     ----                                               ------
Cmdlet          Add-PackageSource                                  OneGet
Cmdlet          Find-Package                                       OneGet
Cmdlet          Get-Package                                        OneGet
Cmdlet          Get-PackageSource                                  OneGet
Cmdlet          Install-Package                                    OneGet
Cmdlet          Remove-PackageSource                               OneGet
Cmdlet          Uninstall-Package                                  OneGet

PS C:\Users\carlo> gcm -Module PowerShellGet

CommandType     Name                                               Source
-----------     ----                                               ------
Function        Find-Module                                        PowerShellGet
Function        Install-Module                                     PowerShellGet
Function        Publish-Module                                     PowerShellGet
Function        Update-Module                                      PowerShellGet
These three new modules confirm Powershell as being the 'glue' which Microsoft wants to push in the limelight as the key tool for a holistic view of the DataCenter, as stated in the DAL:

"The datacenter abstraction layer (DAL) is our work with the industry to provide a common management abstraction for all the resources of a data center to make it simple and easy to adopt and deploy cloud computing. The DAL is not specific to one operating system; it benefits UNIX cloud-computing efforts every bit as much as Windows.

The DAL uses the existing DMTF standards-based management stack to manage all the resources of a data center: physical servers, storage devices, networking devices, hypervisors, operating systems, application frameworks, services, and applications. The DAL is different than other cloud efforts in that it uses - and builds on - proven management stack technologies, instead of inventing new ones."

As a matter of fact, for the moment there is no real tutorial for the usage of these network switch management Cmdlets:
PS C:\Users\carlo> man Get-NetworkSwitchVlan -Online
Get-Help : The online version of this Help topic cannot be displayed because the Internet address (URI) of the Help
topic is not specified in the command code or in the help file for the command.
At line:55 char:7
+       Get-Help @PSBoundParameters | more
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-Help], PSInvalidOperationException
    + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.GetHelpCommand
While this is fully understandable (this is a Preview), I think that this reduces the explorability of those cmdlets and does not encourage IT staff to give them a try for the moment.

What it's clear reading the syntax instructions is that those cmdlets rely on CIM and then to manage the Layer 2 switches you will need to create CIM session connections:
PS C:\Users\carlo> man Get-NetworkSwitchVlan -full


    Get-NetworkSwitchVlan -CimSession  [-Name ]  []

    Get-NetworkSwitchVlan -CimSession  -VlanId   []

    Get-NetworkSwitchVlan -CimSession  -InstanceId   []

    Get-NetworkSwitchVlan -CimSession  -Caption   []

    Get-NetworkSwitchVlan -CimSession  -Description   []
The second Powershell improvement that comes with the WMF 5.0 is the introduction of OneGet module, which can be used to download packages from Chocolatey. The first time you run the Find-Package cmdlet, it asks for the permission to download NuGet:
Just from a first look to the previous screenshot, I can see that this is going to be funny! Just look at the following command:
PS C:\Users\carlo> Find-Package antivirus

Name                             Version          Status           Source
----                             -------          ------           ------
ad-awarefreeantivirus            11.2.5952.0      Available        chocolatey
avastfreeantivirus               9.0.2018         Available        chocolatey
AvgAntivirusBusiness             2013.3349        Available        chocolatey
avgantivirusfree                 14.0.4592        Available        chocolatey
avirafreeantivirus            Available        chocolatey
This is simply great! I can choose an antivirus to install and get it on my test machine using Powershell. What else?

Let's proceed with the installation of Avast!. The process is a breeze:
Install-Package avastfreeantivirus
As you can see in Resource Monitor, Powershell itself is downloading the source file and saving it to C:\Users\carlo\AppData\Local\Temp\2\Microsoft.OneGet.Utility\2\chocolatey\avastfreeantivirus
In my case the installation failed because Avast! can't be installed on a Windows Server version. So Find-Package does not shows us only packages which are available for our platform but all of them and it's up to the admin to choose the right ones to install:
Interesting enough, OneGet gives the possibility to install the Powershell Module for Azure. Nice shot!
PS C:\Users\carlo> find-package azure

Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
AzureBuildSDKvs2012              2.2.2            Available        chocolatey     Azure
AzureConnectDnsSync              1.0.0            Available        chocolatey
AzureStorageExplorer             Available        chocolatey     Azure
Boxstarter.Azure                 2.4.15           Available        chocolatey
CloudBerryExplorer.AzureStorage         Available        chocolatey     Cloud
Dogtail.AzureSDK                 11.2.13230.3     Available        chocolatey
Dogtail.AzureSDK.2.1.VisualSt... 11.2.13230.3     Available        chocolatey
Sogeti.WindowsAzure.Plugins.E... 1.0.0            Available        chocolatey     A Win
WindowsAzureLibrariesForNet      2.2.20140119     Available        chocolatey
WindowsAzureLibsForNet           2.2.20140128     Available        chocolatey
WindowsAzurePowershell           0.8.0            Available        chocolatey
Let's see if can make it through this time:
PS C:\Users\carlo> Install-Package windowsazurepowershell

Installing Package 'WindowsAzurePowershell' from untrusted source
WARNING: This package source is not marked as safe. Are you sure you want to install software from 'chocolatey'
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):

Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
DotNet4.5                        4.5.20120822     Installed        chocolatey     The Microsoft .NET Framework 4.5
Install-Package : Process Failed:msiexec.exe
At line:1 char:1
+ Install-Package windowsazurepowershell
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package],
    + FullyQualifiedErrorId : errorid,Microsoft.PowerShell.OneGet.CmdLets.InstallPackage
The good thing is that Install-Package detects a dependency from DotNet 4.5 and gets this package too.
The bad thing is the installation fails (probably because OneGet and Chocolatey do not handle well the transition to msiexec), and that the failed package is wrongly shown as properly installed:
PS C:\Users\carlo> Get-Package

Name                             Version          Status           Source
----                             -------          ------           ------
avastfreeantivirus               9.0.2018         Installed        Local File
DotNet4.5                        4.5.20120822     Installed        Local File
WindowsAzurePowershell           0.8.0            Installed        Local File
Let's try again with more standard applications: Notepad++ and Vlc:
PS C:\Users\carlo> Install-Package notepadplusplus,vlc

Installing Package 'notepadplusplus' from untrusted source
WARNING: This package source is not marked as safe. Are you sure you want to install software from 'chocolatey'
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):

Name                             Version          Status           Source
----                             -------          ------           ------
notepadplusplus.install          6.6.4            Installed        chocolatey
notepadplusplus                  6.6.4            Installed        chocolatey
vlc                              2.1.3            Installed        chocolatey
This one worked, since I can see Notepad++ and Vlc in the list of the installed Apps. Good.
So, concerning OneGet, I can see that, while experimental, this is pretty wonderful stuff. In the future it would be nice to have an option to update installed packages when a new version becomes available, but, nonetheless, this is a great improvement to Powershell as a management language.

To complete this post, let me mention that the PowerShell Team also added the PowerShellGet module in the May 2014 update to the v5.0 Preview. It comes with an official Microsoft repository for pulling in the latest modules. The first time you use it, it ask for the permission to install NuGet.exe:
PS C:\Users\carlo> find-module

NuGet.exe is required to continue.
PowerShellGet requires NuGet.exe to interact with NuGet based galleries. NuGet.exe must be available in
'C:\Users\carlo\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet'. For more information about NuGet, see Do you want PowerShellGet to download NuGet.exe to
'C:\Users\carlo\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet' now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):

Version         Name                                     DateUpdated               Description
-------         ----                                     -----------               -----------         AutoVars                                 6/6/2014 11:38:07 PM      Allows for t
2.0             BetterCredentials                        6/6/2014 4:28:03 PM       A (compatibl
5.0             Bing                                     6/6/2014 4:28:03 PM       A few functi         CimInventory                             6/6/2014 4:28:03 PM       Module that
6.0             ConversionModule                         6/6/2014 4:28:03 PM       a module tha
1.0             EWS                                      6/8/2014 12:33:11 PM      Module to en         FAQ                                      6/6/2014 4:28:03 PM       A Frequently
1.0             GenericMethods                           6/6/2014 4:28:03 PM       The Invoke-G         HardwareManagement                       6/6/2014 4:28:03 PM       Out-of-band
1.1             IEFavorites                              6/6/2014 4:28:03 PM       Used to mana
1.0             InlineMailAttachments                    6/6/2014 4:28:03 PM       This module         ISEGit                                   6/6/2014 11:48:07 PM      Module to wo
3.0             LocalUserManagement                      6/6/2014 11:28:07 PM      a module tha         LockObject                               6/6/2014 4:28:03 PM       Lock-Object         MyDefaults                               6/6/2014 11:38:07 PM      Sets and get
1.4             myModule                                 6/6/2014 4:28:03 PM       My PowerShel         poke                                     6/6/2014 4:28:03 PM       A PowerShell
1.0             Posh-Shodan                              6/6/2014 4:28:03 PM       Module for i
1.2             Posh-VirusTotal                          6/5/2014 12:28:40 AM      PowerShell m
1.0             PoshInternals                            6/5/2014 12:28:40 AM      Collection o
1.0             PoshNet                                  6/5/2014 4:39:40 PM       Get-DNS is "
2.2.1           PoshWSUS                                 6/5/2014 4:39:40 PM       PowerShell m
3.6             PowerBot                                 6/5/2014 12:28:40 AM      PowerBot: th
0.4             PowerEvents                              6/5/2014 4:34:40 PM       PowerEvents
1.2             PowerShellCookbook                       6/8/2014 1:03:09 AM       Sample scrip
1.2             PowerShellHumanizer                      6/5/2014 4:39:40 PM       PowerShell H
4.0             PowerShellISEModule                      6/6/2014 6:23:03 PM       a module tha         PowerShellLogging                        6/5/2014 4:39:40 PM       Captures Pow
1.0             PreferenceVariables                      5/28/2014 5:47:54 PM      The Get-Call         Pscx                                     6/4/2014 8:58:40 PM       PowerShell C         PSReadline                               6/5/2014 4:39:40 PM       Great comman
2.4             ResolveAlias                             6/5/2014 12:28:40 AM      A function f         ScriptBrowser                            6/5/2014 12:28:40 AM      Script Brows         ScriptCS                                 6/5/2014 4:39:40 PM       Allows execu
1.0             ScriptTransforms                         5/28/2014 5:47:54 PM      Enables you        ScsmPx                                   5/28/2014 5:47:54 PM      The ScsmPx m         SNMP                                     6/6/2014 9:03:06 PM       Module to ma
2.0             SQLite                                   6/5/2014 4:39:40 PM       The SQLite P
1.0             StringTokens                             6/5/2014 4:39:40 PM       The Get-Stri         StrongNaming                             5/28/2014 5:47:54 PM      The Strong N
1.1             TCPServer                                6/5/2014 12:28:40 AM      Module used         TestConnectionAsync                      6/5/2014 4:39:40 PM       Test-Connect         TxF                                      6/5/2014 4:39:40 PM       Provides tra         TypeAccelerator                          5/28/2014 5:47:54 PM      The TypeAcce
2.0             xActiveDirectory                         6/7/2014 2:08:09 PM       The xActiveD
0.1.0           xAzure                                   6/7/2014 2:13:09 PM       The xAzure m
1.1.5           xAzureVMResources                        6/7/2014 1:08:09 PM       Module with
1.2.1           xComputerManagement                      6/7/2014 2:08:09 PM       The xCompute
1.1.1           xDatabase                                6/7/2014 2:08:09 PM       The xDatabas
1.0             xDhcpServer                              6/7/2014 2:13:09 PM       The xDhcpSer
1.0             xDnsServer                               6/7/2014 2:13:09 PM       The xDnsServ
2.0             xDscDiagnostics                          6/7/2014 2:08:09 PM       Module to he
1.1.1           xDSCResourceDesigner                     6/7/2014 2:08:09 PM       The xDscReso         xEXOUserAvailability                     6/7/2014 1:08:09 PM       xEXOUserAvai
1.1.1           xFailOverCluster                         6/7/2014 2:08:09 PM       The xFailOve
2.1.1           xHyper-V                                 6/7/2014 2:08:09 PM       The xHyper-V        xJea                                     6/7/2014 12:48:07 AM      Module with
2.1.1           xNetworking                              6/7/2014 2:08:09 PM       The xNetwork
1.0.0           xOneGet                                  6/7/2014 2:13:09 PM       DSC Resource         xPSDesiredStateConfiguration             6/7/2014 2:08:09 PM       The xPSDesir
1.0.1           xRemoteDesktopSessionHost                6/7/2014 2:08:09 PM       The xRemoteD
1.0.1           xSmbShare                                6/7/2014 2:08:09 PM       The xSmbShar
1.1.2           xSqlPs                                   6/7/2014 2:08:09 PM       The xSqlPs m
1.0.1           xSystemSecurity                          6/6/2014 12:58:02 PM      The xSystemS
1.3.1           xWebAdministration                       6/7/2014 2:08:09 PM       The xWebAdmi
1.0             xWindowsUpdate                           6/7/2014 2:13:09 PM       Module with         xWinEventLog                             6/7/2014 2:13:09 PM       Configure Wi
A new world opens, with so many modules available for use. In a next post I will decisively continue exploring the new functionalities and features of Powershell 5.0. So stay tuned!

1 comment:

  1. The problem is that until this has a gui frontend that is on the menu somewhere, no one is ever going to find it or even think to use it, let alone use it.


Related Posts Plugin for WordPress, Blogger...