PowerShell for Windows Admins


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.


June 27, 2016  12:57 PM

PowerShell Summit & Conference videos 2016

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

If you didn’t get to any of these conferences this year the videos are now available.

PowerShell and DevOps Summit

https://www.youtube.com/playlist?list=PLfeA8kIs7Coc1Jn5hC4e_XgbFUaS5jY2i

 

European PowerShell Conference

https://www.youtube.com/channel/UCxgrI58XiKnDDByjhRJs5fg

You might find this interesting as well.

WinOps conference

https://www.youtube.com/channel/UCP1OgsLk-HkEdQyhjJX_5JQ


June 26, 2016  5:13 AM

Too many Windows 10 releases????????

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Windows 10

The last couple of days have seen some incredibly stupid headlines but one that caught my eye was someone from the “computer press” whining that there are too many releases of Windows 10.

Unbelievable

What part of the Windows Insider Preview program does this person not understand?

You have to sign up to get Windows Insider Previews!

You have a choice of the fast ring (all releases) or the slow ring (fewer releases).

if you don’t want new releases take your self off the program!

Bet we’d get whines that Microsoft wasn’t doing enough releases if they went back to 1 every three or more years.

Complain about technical problems by all means but something you signed up to do!

Needless to say I’ve dropped that feed


June 25, 2016  9:17 AM

Parallel processing

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

One of the great features PowerShell brings is the ability to remotely administer your servers. Most people begin remote administration by processing the servers sequentially. Eventually, this process breaks down because you have too many servers and/or the processes you are running against each server are long running.

At this point you have to consider parallel processing.

The UK TechNet blog has recently published my article on the options for parallel processing using various PowerShell techniques

https://blogs.technet.microsoft.com/uktechnet/2016/06/20/parallel-processing-with-powershell/


June 12, 2016  4:22 AM

Months

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

It would be nice to be able to do this:

PS>  Get-Date -Day 25 -Month December -Year 2016
Get-Date : Cannot bind parameter ‘Month’. Cannot convert value “December” to type “System.Int32”.
Error: “Input string was not in a correct format.”
At line:1 char:25
+ Get-Date -Day 25 -Month December -Year 2016
+                         ~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Get-Date], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCo
mmand

You have to do this:

PS>  Get-Date -Day 25 -Month 12 -Year 2016

25 December 2016 11:00:56

The time is set to current time automatically.

One of the gaps in .NET is an enum for the months of the year. You get an enum for days of the week:

PS>  [System.DayOfWeek]::Friday
Friday

PS>  0..6 | foreach {[System.DayOfWeek]$psitem}
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday

PowerShell v5 gives you the capability to make your own enums:

enum MonthsOfYear {
January = 1
February = 2
March = 3
April = 4
May = 5
June = 6
July = 7
August = 8
September = 9
October = 10
November = 11
December = 12
}

PS>  [MonthsOfYear]10
October
PS>  [MonthsOfYear]::April
April

PS>  1..12 | foreach {[MonthsoFYear]$PSItem}
January
February
March
April
May
June
July
August
September
October
November
December

PS>  [System.Enum]::GetNames([MonthsOfYear])
January
February
March
April
May
June
July
August
September
October
November
December

Now you can use the name of the month

PS>  Get-Date -Day 25 -Month ([MonthsOfYear]::December) -Year 2016

25 December 2016 11:19:38

Enums are one of those pieces of functionality that you don’t necessarily think about but are very useful. The ability to create your own in PowerShell is very useful and will become more widespread as people realise its available.


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: