PowerShell for Windows Admins

July 21, 2016  1:58 PM

Parallel copy files over remoting session

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

In response to this post – https://richardspowershellblog.wordpress.com/2015/05/28/copy-files-over-ps-remoting-sessions/

I was asked how you could copy files in parallel to multiple machines.

As soon as anyone mentions parallelism I think of workflows so I ended up with this

$computers = ‘W16TP5TGT01’, ‘W16TP5TGT02’

workflow parallelcopy {
param ([string[]]$computername)
foreach -parallel ($computer in $computername) {
InlineScript {
$s = New-PSSession -ComputerName $using:computer
Copy-Item -Path C:\Scripts\New-NanoMachine.ps1 -Destination C:\Source -ToSession $s
Remove-PSSession -Session $s

parallelcopy -computername $computers

A couple of issues I found. First off –Tosession and –FromSession haven’t been added to the Copy-Item workflow activity. This means you have to use an Inline script block to access those parameters

Secondly accessing a emoting session created outside of the workflow generates a session busy error when trying to perform the copy so have to move the session creation into the Inline script.

If you had a lot of files, or a lot of data, to copy to multiple machines this approach may be worthwhile. For small amounts of data then the approach in the original article is probably best.

July 18, 2016  4:49 AM

Manning Deal of the Day 19 July 2016

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Active Directory, Books

Deal of the Day July 19: Half off my book Learn Active Directory Management in a Month of Lunches. Use code dotd071916au at https://bit.ly/2a8jroO

For more information on Manning’s Deal of the Day see –  https://www.manning.com/dotd.

July 15, 2016  5:20 AM

Biggest innovation in PowerShell is…

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The imminent arrival of PowerShell 5.1 in the Windows 10 Anniversary update (assumption as the Windows 10 Insider previews have been showing PowerShell 5.1 for some time) and Windows Server 2016 (TP5 shows PowerShell 5.1) and the fact that PowerShell was officially released to the world 10 years ago come November started me thinking about what has been the biggest innovation in PowerShell over those 10 years.

Contenders that come to mind include:

– Remoting
– PowerShell modules
– CIM & CIM sessions
– Workflows
– Job engine
– Desired State Configuration
– PowerShell Gallery and package management
– PowerShell classes
– JSON support in PowerShell
– Internationalisation
– Error handling – try/catch
– Debugging enhancements
– REST API and Odata support
– PowerShell support for Microsoft products
– PowerShell support from third part vendors
– PowerShell community

Which do you think?

Or is it something else?

Leave a comment as I’m intrigued as to what people think has been the biggest PowerShell innovation

July 13, 2016  7:43 AM

Summer goodies

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Windows 10, Windows Server 2016

Looks like we’re set for some summer goodies over the next few months.

First up is Windows 10 anniversary update that’s due 2 August


Followed by the Windows Server 2016 launch at the end of September


TP5 is stated to be feature complete – my testing so far shows some rough edges. Hope launch means general availability and not another 2-3 month wait like we had with Windows 2012 R2

The article is also interesting for showing how Windows server and Nano server will be treated differently. Windows server wil get patches in the traditional cycle we’ve come to know and love(?). Nano server will be more like Windows 10 with updates 2-3 times per year – including new features. Hopefully that would include Nano server being able to support more roles

July 12, 2016  12:55 PM

Copying across multiple remoting sessions

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell, Windows Server 2016

I needed to copy the same file to multiple machines so I tried this:

$computers = ‘W16CN01’, ‘W16CN02’

$s = New-PSSession -ComputerName $computers

Copy-Item -Path ‘C:\Source\Windows 2016 TP5\Cumulative Update for Windows Server 2016 Technical Preview 5 (KB3163016)\AMD64-all-windows10.0-kb3163016-x64_83d6e9bca94a64a5d9be3d81cdb182e540285848.msu’ -Destination C:\Scripts -ToSession $s

Remove-PSSession –Session $s

It failed with:

Copy-Item : Cannot convert ‘System.Object[]’ to the type
‘System.Management.Automation.Runspaces.PSSession’ required by parameter
‘ToSession’. Specified method is not supported.
At line:5 char:236
+ … a5d9be3d81cdb182e540285848.msu’ -Destination C:\Scripts -ToSession $s
+                                                                        ~~
+ CategoryInfo          : InvalidArgument: (:) [Copy-Item], ParameterBindi
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Comma

If you look at the syntax

Get-Command Copy-Item -Syntax

Copy-Item [-Path] <string[]> [[-Destination] <string>] [-Container]
[-Force] [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>]
[-Recurse] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm]
[-UseTransaction] [-FromSession <PSSession>] [-ToSession <PSSession>]

Copy-Item [[-Destination] <string>] -LiteralPath <string[]> [-Container]
[-Force] [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>]
[-Recurse] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm]
[-UseTransaction] [-FromSession <PSSession>] [-ToSession <PSSession>]

the ToSession and FromSession parameters only take a single session as their value.

Modify the code to

$computers = ‘W16CN01’, ‘W16CN02’

$sessions = New-PSSession -ComputerName $computers

foreach ($session in $sessions) {
Copy-Item -Path ‘C:\Source\Windows 2016 TP5\Cumulative Update for Windows Server 2016 Technical Preview 5 (KB3163016)\AMD64-all-windows10.0-kb3163016-x64_83d6e9bca94a64a5d9be3d81cdb182e540285848.msu’ -Destination C:\Scripts -ToSession $session

Remove-PSSession -Session $sessions

And it works

July 8, 2016  8:37 AM

PowerShell Direct example

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Hyper-V, Powershell, Virtualization, Windows Server 2016

Last week I mentioned PowerShell and how you can create a PowerShell Remoting session to a Virtual Machine that’s running on Hyper-V

Here’s an example of it in use:

$cred = Get-Credential W16TP5TGT01\Administrator
$s = New-PSSession -VMName W16TP5TGT01 -Credential $cred

Create the credential for the VM and then create the remoting session. I prefer to use the VM name rather than the GUID.

Once you’ve established the session you can use it. In this case I’m using another PowerShell 5.o innovation to copy a file across the remote session:

Copy-Item -Path ‘C:\Source\Windows 2016 TP5\Cumulative Update for Windows Server 2016 Technical Preview 5 (KB3163016)\AMD64-all-windows10.0-kb3163016-x64_83d6e9bca94a64a5d9be3d81cdb182e540285848.msu’ -Destination c:\source -ToSession $s

Clean up as usual:

Remove-PSSession -Session $s

PowerShell Direct is another useful addition to the remoting toolbox. It’ll be especially useful in non-domain remoting situations.

July 6, 2016  12:29 PM

DSC and Nano Server

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
DSC, Nano server, Windows Server 2016

Nano Server is the minimalist version of Windows that Server 2016 introduces. I needed a target for DSC this afternoon so decided that I’d spin up a Nano Server instance – because they are very, very quick to create.

Unfortunately, Nano Server doesn’t support DSC out of the box. The ROOT\Microsoft\Windows\DesiredStateConfiguration CIM namespace isn’t available for instance.

You need to add the DSC bits when you create your Nano server – use

-Packages Microsoft-NanoServer-DSC-Package

on New-NanoServerImage when you generate the Nano server virtual disk.

see https://msdn.microsoft.com/powershell/dsc/nanodsc

for current restrictions and limitations of DSC on Nano server

July 5, 2016  9:46 AM

PowerShell 2.0 Engine removed from Server 2016

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell, Windows Server 2016

I hadn’t realised that the PowerShell 2.0 engine had been removed from Windows Server 2016 TP5

PS C:\Windows\system32> Get-WindowsFeature  PowerShell-V2 | ft -a

Display Name                          Name          Install State
————                          —-          ————-
[ ] Windows PowerShell 2.0 Engine PowerShell-V2       Removed

Probably about time it disappeared. Can’t think of a reason you’d need it on Server 2016

July 4, 2016  12:59 PM

Some potentially useful modules

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I’ve come across a number of modules over the last few months that may be of interest. In no particular order:

PSDEPLOY – https://github.com/RamblingCookieMonster/PSDeploy

A module to simplify PowerShell based deployments

PLASTER – https://github.com/PowerShell/Plaster

A template based artifact generator – streamlines creation of PowerShell module projects, pester tests, DSC configurations etc

OPERATION VALIDATION FRAMEWORK –https://github.com/PowerShell/Operation-Validation-Framework

Tools for executing validation of the operation of a system. Organises and executes Pester tests to validate operation

LABILITY – https://www.powershellgallery.com/packages/Lability/0.9.8

Provisioning Hyper-V test lab and development environments

PSAKE  – https://github.com/psake/psake

Build automation

POSHSPEC – https://github.com/Ticketmaster/poshspec

Infrastructure testing DSL. Expanding Pester to test infrastructure

Some of these projects are just starting while others are more mature.

They may not do exactly what you want but they may give you some ideas. All of these are well worth a look

July 3, 2016  3:54 AM

Administering Windows Containers

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Windows Server 2016

Containers have been available in the Linux world for some time. Server 2016 brings them to the Windows world.

The concept of containers is easy – they are a lightweight virtualisation option for application delivery. Think of them as an extremely light weight virtual ‘machine’. Machine is in quotes because they aren’t virtual machines. they do use Hyper-V’s virtualisation capabilities in certain scenarios.

Administering containers in Windows Server 2016 TP5 is an “interesting” challenge. You have a number of options:

First off there isn’t a GUI admin tool

Secondly, there’s a PowerShell module that installs with the Containers feature. This is marked as deprecated however.

Thirdly, you can download and install Docker for Windows but it isn’t complete. Docker for Windows and the original PowerShell module are incompatible in that they can’t work with containers created with the tool – they can’t even see them. The MSDN documentation seems to prefer Docker for administering containers.

Fourthly, there’s a new PowerShell module that is under development. It doesn’t have an ETA and if you want to trial it you have to compile the code yourself. This new PowerShell module uses the Docker REST API so you HAVE to install Docker.

Nano server is a very small footprint install option introduced in Server 2016. Running containers on Nano server is an ideal combination – assuming your applications will run on Nano server. In my opinion having to install Docker on my Nano server negates its premise.

In addition Docker is constantly evolving. Will Docker for Windows evolve at the same rate and will the new PowerShell module keep up.

Interesting questions that can’t be answered at present. Hopefully, the next iteration of Server 2016 might answer some of these questions. TP5 was released in April and hasn’t been as stable as TP4 in my experience. That plus the wireless connectivity issues that have only been partially resolved leave me hoping for a new version soon.

Whatever happens I suspect you’ll have to learn Docker with its arcane command syntax whether you want to or not.

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: