PowerShell for Windows Admins

January 5, 2019  7:07 AM

Windows sandbox

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Windows 10

The recent Windows 10 Insider builds (18305) have introduced a Windows sandbox feature. This is a new light weight desktop environment for testing software. A new sandbox is created every time you need one and EVERYTHING in the sandbox is destroyed when you close it.

see https://blogs.windows.com/windowsexperience/2018/12/19/announcing-windows-10-insider-preview-build-18305/#ua844cXgClodRKz2.97 for the initial announcement.

The IE fix KB4483214 seems to break the sandbox on build 18305.

I’ve tried it on build 18309 and it seems to work OK.

There are a few issues as explained in the blog post and the documentation


Note the requirement to enable nested virtualisation if you’re running the preview in a VM.

So far it looks like one of the more useful features to come out of the Windows 10 update process.

January 3, 2019  7:33 AM

More PowerShell v6 thoughts

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

My last post  – about PowerShell v6 – brought some interesting comments. Here’s some more PowerShell v6 thoughts generated by those comments.

Comment Quote 1

“What’s the incentive to upgrade on Windows from 5.1 to 6.x? My understanding is that not all functionality is present in the open source version (specifically, WIM and COM). It’s not functionality that I use, personally, but I don’t see much reason to “upgrade” while the new version is still working to reach feature parity. “


PowerShell v6 supports COM.  I don’t use WIM so don’t know how much WIM support is available in Windows PowerShell. If it was meant to be WMI then v6 has always included the CIM cmdlets which are a better choice than the WMI cmdlets. The WMI accelerators are also available in v6 if you need them.

All of the CDXML (CIM/WMI) based modules that I’ve tested work in v6.

Comment Quote 2

“Also, and this is not as trivial as it seems, the command name changes from “powershell” to the incredibly ugly “pwsh” – which will wreak havoc with many scripts and people’s muscle memory”


The official reason for the introduction of pwsh was that it was confusing having 2 powershell.exe on the PATH when you have v6 and v5.1 installed on the same machine. Having said that the thread that introduced the change was originally about reducing the length of the executable name because Linux users didn’t want to type powershell – it was deemed to be too long! Pwsh was a compromise and like all compromises usually pleases no one.

Comment Quote 3

“So I think that all this data shows is that Powershell 6.x is growing in popularity on Linux, but it’s not yet an attractive alternative to 5.x for Windows users. I certainly hope that the message Microsoft take from the figures is that they’ve got some way to go yet to persuade Windows users that the new Powershell is an actual improvement, and not to further abandon Windows Powershell users!”


The problem with PowerShell on Linux is that much of the PowerShell functionality we take for granted on Windows – networking, storage, WMI – just  isn’t available on Linux. There isn’t much on the gallery either for Linux as far as I can see. So why the great usage on Linux? To my mind PowerShell on Linux is currently around the Windows PowerShell  v1-v2 level for functionality.

The WindowsCompatibility module makes most, if not all, Windows PowerShell modules work in v6 but its a workaround not a long term solution.

I have a lot of difficulty understanding where PowerShell v6 is going – hopefully more will be revealed in 2019.

Comment Quote 4

“If I can’t do ActiveDirectory administration with V6 then it is a show stopper in most “Windows” shops”


On Windows  10 1809 / Server 1809 / Server 2019 the AD module works in PowerShell v6.1.1 EXCEPT when trying to access or modify the protected from accidental deletion attribute.

The AD module works in PowerShell v6.1.1 via the WindowsCompatibility module on earlier versions of windows

January 2, 2019  12:23 PM

PowerShell dashboard

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The PowerShell dashboard shows some interesting data:



Linux is by far the dominant platform for PowerShell v6 usage – about 4 times as much usage on Linux as Windows for December 2018!  Does this mean that PowerShell is destined to become a Linux orientated tool?  It has been stated by the PowerShell team that usage patterns will drive development so Windows users need to step up if they want input into future PowerShell


PowerShell 6.1 is taking over from 6.0 but a significant number of users are still using 6.0 and 6.1 previews – Why?


Very little V6.2 preview usage is recorded


Windows 10 is the dominant Windows version for PowerShell v6


North America accounts for just over half the v6 usage. UK is next at 4.91%.  Time for the rest of the world to contribute?


PowerShell is now open source and as such will be driven by “the community” in other words those how get involved and push their needs and/or pet views of where PowerShell will go. Is that a good thing?


The idea behind Windows PowerShell was for it to become the de facto scripting language and automation engine on Windows. It succeeded. What is the long term PowerShell v6 goal? Is to become the de facto cross-platform scripting language and automation engine? if so there needs to be a ton of functionality appear so that Linux can be managed at the same level as Windows.

December 31, 2018  11:11 AM

PowerShell articles

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Here’s some links for other PowerShell articles I’ve written recently







December 30, 2018  7:39 AM

Change file times

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

When a file is created, accessed or modified that time is recorded. This is how to change file times.

There are three properties to consider:





Just to add to the fun there are UTC (GMT in real world) times as well:




If you need to change a property its a set operation. For instance

Get-ChildItem -Path x9.txt | foreach {$_.LastWriteTime = ($_.LastWriteTime).AddHours(6)}


Substitute the appropriate property as required. If you change a property the UTC version is changed in step – accounting for timezone differences

December 29, 2018  3:58 PM

Get first non-repeating character in a string

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

How do you get first non-repeating character in a string.

In Windows PowerShell v5.1 you could use Group-Object but as I showed last time that approach has been taken away in PowerShell v6.1.

Instead you need to loop through the characters in the string and count them


Input the test string through a parameter. Create an ORDERED hash table for the results – you need to preserve the order in which characters are counted!

Convert the string to lowercase (remove this step if your worried about case) and convert to an array of chars. Pipe into foreach-object. Test is the character is already in the hashtable. If it is increment the count. If it isn’t add it.

Use the getEnumerator() method to access the hash table. use where-object to filter for characters only appearing once. Select the first one.

December 29, 2018  9:16 AM

Group-Object change in PowerShell v6.1

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

There’s a subtle Group-Object change in PowerShell v6.1.

In PowerShell v5.1 if you do this:

$ts = ‘ffrluoluntlvxutxbdvbktgyyvsvcrkxoyfotzkzogcwuwycmnhuedk’
$ts.ToCharArray() | group


You get this:

Count Name                  Group
----- ----                  -----
    3    f                  {f, f, f}
    2    r                  {r, r}
    3    l                  {l, l, l}
    5    u                  {u, u, u, u...}
    4    o                  {o, o, o, o}
    2    n                  {n, n}
    4    t                  {t, t, t, t}
    4    v                  {v, v, v, v}
    3    x                  {x, x, x}
    2    b                  {b, b}
    2    d                  {d, d}
    4    k                  {k, k, k, k}
    2    g                  {g, g}
    4    y                  {y, y, y, y}
    1    s                  {s}
    3    c                  {c, c, c}
    2    z                  {z, z}
    2    w                  {w, w}
    1    m                  {m}
    1    h                  {h}
    1    e                  {e}


If you repeat the exercise in PowerShell v6.1 you get this:

Count Name                      Group
----- ----                      -----
    2    b                      {b, b}
    3    c                      {c, c, c}
    2    d                      {d, d}
    1    e                      {e}
    3    f                      {f, f, f}
    2    g                      {g, g}
    1    h                      {h}
    4    k                      {k, k, k, k}
    3    l                      {l, l, l}
    1    m                      {m}
    2    n                      {n, n}
    4    o                      {o, o, o, o}
    2    r                      {r, r}
    1    s                      {s}
    4    t                      {t, t, t, t}
    5    u                      {u, u, u, u...}
    4    v                      {v, v, v, v}
    2    w                      {w, w}
    3    x                      {x, x, x}
    4    y                      {y, y, y, y}
    2    z                      {z, z}


In PowerShell v6.1 the results are automatically sorted by the Name (the same behaviour is exhibited in PowerShell v6.2 preview 3).  That may, or may not, be what you want. Not sure exactly when, or even why, this behaviour changed.


When I’m using Group-Object I’m usually looking for the most or least common item so I tend to sort on value.


I don’t understand the value of this change and suspect its yet another change to PowerShell that was introduced to meet someone’s pet view of the world – one of the major problems of open source projects no one seems to really apply the “just because we can doesn’t mean we should filter”.

December 28, 2018  1:50 PM

Counting vowels

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

If you’re given a string how would you go about counting vowels, consonants  and non-alphabet characters.

My approach would be:



The string to test is an input parameter.  Set up the output hash table and the byte value of the vowels.

Convert the string to lowercase and then to a char array which is put on the pipeline. Convert the char to a byte value and then use the switch statement to determine if its a vowel, consonant or non-alphabetic character.

Finally output the results.

December 27, 2018  7:11 AM

Create a random string

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I often need to create a random string of characters. Here’s a simple function to achieve that:


The required length is passed as an integer parameter.  Use the range operator as a counter and in Foreach-Object generate a random number between 97 and 122.  Convert that to a char  (a=97 and z-122) and add to the array.  Join the array of chars to create the string.

December 12, 2018  12:43 PM

Return of the missing PSDiagnostics

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Return of the missing PSDiagnostics members in PowerShell v6.2 preview 3.

In Windows PowerShell v5.1 the PSDiagnostics module contains these members:



In PowerShell v6.1.1 you just get these:



Quite a few missing.

In PowerShell v6.2 preview 3 we’re back to the original set:



NOTE: this is just on Windows – I don’t have a non-Windows machine to determine what’s available on  non-Windows platforms

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: