Windows sandbox

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

https://techcommunity.microsoft.com/t5/Windows-Kernel-Internals/Windows-Sandbox/ba-p/301849

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.

Advertisements
Posted in Windows 10 | Leave a comment

More PowerShell v6 thoughts

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. “

Reply:

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”

Reply:

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!”

Reply:

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”

Reply:

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

Posted in PowerShell v6 | 6 Comments

PowerShell dashboard

The PowerShell dashboard shows some interesting data:

https://msit.powerbi.com/view?r=eyJrIjoiYTYyN2U3ODgtMjBlMi00MGM1LWI0ZjctMmQ3MzE2ZDNkMzIyIiwidCI6IjcyZjk4OGJmLTg2ZjEtNDFhZi05MWFiLTJkN2NkMDExZGI0NyIsImMiOjV9&pageName=ReportSection5

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.

Posted in PowerShell v6 | 2 Comments

PowerShell articles

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

https://searchwindowsserver.techtarget.com/tip/PowerShell-commands-to-copy-files-Basic-to-advanced-methods

https://searchwindowsserver.techtarget.com/tutorial/PowerShell-commands-for-Active-Directory-Groups-management

https://searchwindowsserver.techtarget.com/tip/PowerShell-Core-61-offers-many-small-improvements

https://searchwindowsserver.techtarget.com/tutorial/How-PowerShell-Direct-helps-polish-off-those-VMs

https://searchwindowsserver.techtarget.com/tutorial/Working-with-PowerShell-module-downloads-from-the-gallery

Enjoy

Posted in Powershell | Leave a comment

Change file times

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:

CreationTime

LastAccessTime

LastWriteTime

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

CreationTimeUtc

LastAccessTimeUtc

LastWriteTimeUtc

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

Posted in Powershell | 1 Comment

Get first non-repeating character in a string

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

function get-firstnonrepeatcharacter {
   [CmdletBinding()]
   param (
     [string]$teststring
   )

  $a = [ordered]@{}

  $teststring.ToLower().ToCharArray() |
   foreach {
     if ($a.$psitem) {
       $a.$psitem += 1
     }
     else {
       $a += @{$psitem = 1}
     }

  }

  $a.GetEnumerator() | where Value -eq 1 | select -First 1

}

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.

$ts = ‘lcoauywfnqumfheolfzaliigngulxqdbnzprnylfqvsxathrqsyjowm’

PS> get-firstnonrepeatcharacter -teststring $ts 

Name Value
—-      —–
c          1

Posted in Powershell | Leave a comment

Group-Object change in PowerShell v6.1

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”.

Posted in PowerShell v5, PowerShell v6 | Leave a comment