PowerShell for Windows Admins


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
Powershell

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.


July 1, 2016  7:32 AM

First nail in PowerShell’s coffin?

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

The MSDN pages describing the installation and use of containers

https://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/quick_start_images

seems to have removed all of the PowerShell code and just supply examples in Docker.

After 10 years is this the first sign that PowerShell is going away?


July 1, 2016  3:17 AM

PowerShell Direct

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

PowerShell Direct is a PowerShell 5.1 feature available in Windows 2016 TP5 and above and the later builds of Windows 10.

It adds 3 parameters:

-VMId

-VMGuid

-VMName

To these cmdlets

Enter-PSsession

Invoke-Command

New-PSsession

but NOT New-Cimsession

The VMId & ID parameters access a GUID. VMname is probably easiest to use

VMName                : W16TP5SC01
VMId                  : 2fad20ad-5a34-4a55-a7ec-2ec208ec4f0c

The –VMGuid parameter presumably uses the Id property on the VM which matches the GUID in VMId

The great thing about it is that enables you to work remotely with virtual machines – across the VM bus. It therefore bypasses a lot of the problems for remoting to non-domain joined machines. As long as they’re VMs on Hyper-V you’re golden.

I’ve just started experimenting with it but if you’re not using DSC it saves a lot of effort with trusted hosts or certificates when setting up machines.

Once you have a remote session established you can also copy files across it.

You need to run this from the Hyper-V host and you also need the credentials for the remote machine

See – https://msdn.microsoft.com/en-us/virtualization/hyperv_on_windows/user_guide/vmsession


June 30, 2016  10:08 AM

Wireless on Windows 2016 TP5

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Windows Server 2016

Windows Server 2016 TP5 which appeared at the end of April has a major flaw. It doesn’t work with wireless cards!

I use a relatively high-spec laptop as my lab machine. Not being able to get the wireless card working means no Internet access and makes activation a lot more difficult.

The June Cumulative Update KB3163016 appears to fix the issue. https://support.microsoft.com/en-gb/kb/3163016

Install Windows 2016 TP5. Then immediately install KB3163016. Install the Wireless LAN Service (needs a reboot) through Add Roles and features or

Add-WindowsFeature –Name Wireless-Networking

. The Wireless LAN Service defaults to disabled so you’ll need to change the start type to automatic and start the service.

Then you can install whatever Windows features you need.

One thing I’ve noticed is that the wireless card doesn’t seem to keep its connection to the wireless network between reboots. Its an annoyance in a TP would be beyond aggravating in final version


June 29, 2016  10:57 AM

Cleaning up entries on Remote Desktop Connection

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell, Registry settings

I use RDP between my main laptop and the machine on which my lab resides. When I rebuild the lab the entries in the Remote Desktop Connection for the old machine still remain.

There isn’t a direct way to remove those entries. But you can remove them from the registry.

First view the entries

Get-ChildItem -Path ‘HKCU:\SOFTWARE\Microsoft\Terminal Server Client\’
Hive: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Terminal Server Client
Name                           Property
—-                           ——–
Default                        MRU0 : RSLaptop01
MRU1 : serverrs01
MRU2 : server02

The partial list above shows you that the property names are MRU*

You can view individual entries

Get-ItemProperty -Path ‘HKCU:\SOFTWARE\Microsoft\Terminal Server Client\Default\’ -Name MRU2
MRU2         : server02
PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Terminal
Server Client\Default\
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Terminal
Server Client
PSChildName  : Default
PSDrive      : HKCU
PSProvider   : Microsoft.PowerShell.Core\Registry

You can now delete as required – for instance

Remove-ItemProperty -Path ‘HKCU:\SOFTWARE\Microsoft\Terminal Server Client\Default\’ -Name MRU2


June 29, 2016  8:36 AM

Boolean in Where-Object filter

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

I was testing some code yesterday and realised there was a quirk in the way the original where syntax (with {}) worked and the way the newer syntax worked.

To demonstrate this I created a set of objects

$i = 0

$tests = while ($i -lt 25){
New-Object -TypeName PSObject -Property @{
Index = $i
Current = if (-not($i % 2)){$true} else {$false}
}
$i++
}

Object properties are a numeric index and a boolean value

If you want just the $true values many people write this

$tests | where {$_.Current -eq $true}

or if using the newer syntax use this

$tests | where Current -eq $true

This is unnecessary typing as you can do this

$tests | where {$_.Current}

$tests | where Current

The reason is that the filter you are creating tests a property of the current object against your criteria and passes is if the result is true. A boolean property will by definition either be true of false so just need to test directly

if you want to double negative type test i.e. – not $true (which I don’t recommend as its very easy to get into  logic mess) then you have to do this

$tests | where {-not $_.Current}

as this fails
$tests | where –not Current

You could do this

$tests | where Current -ne $true

but it negates the whole code simplification objective


June 28, 2016  10:35 AM

Still asking for topics

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Earlier in the month I posted a request for topics on powershell.org

https://powershell.org/request-for-topics/

This is a request for YOU to tell us what topics you would like to see at the next PowerShell & DevOps Summit

We’ve had a handful of replies so far.

This is your chance to influence the content of the Summit. These topics will be included as suggestions in the Call for Proposals where we ask potential speakers to send us their session proposals. That will be going out next month.

if there is something in the PowerShell/DevOps world you want to know more about let us know.


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: