Installing Linux on Windows 10

Windows 10 comes with Windows Subsystem for Linux (WSL) feature that you can use to run various Linux distributions. Launch a PowerShell with elevated privileges to enable the WSL:

Enable-WindowsOptionalFeature -FeatureName Microsoft-Windows-Subsystem-Linux -Online  

Next, open the Microsoft Store on Windows 10, and search for “Linux”. Install one of the supported Linux distros (for example, Debian)!

That is all that is required. You can now open Debian from within PowerShell or via the start menu. Simply run the “Debian” command. When you do this for the first time, you’ll have to define a root account and password.

As you probably know, PowerShell 6 is platform independent and runs on Linux too. If you wanted to use your new Debian environment to also test-drive PowerShell 6 on Linux, run the following commands from within your Debian console:

sudo apt-get update
sudo apt-get install curl apt-transport-https
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo sh -c 'echo "deb https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/microsoft.list'
sudo apt-get update
sudo apt-get install -y powershell
pwsh

Next, from within Debian, run the “pwsh” command to switch to PowerShell 6.


psconf.eu – PowerShell Conference EU 2019 – June 4-7, Hannover Germany – visit www.psconf.eu There aren’t too many trainings around for experienced PowerShell scripters where you really still learn something new. But there’s one place you don’t want to miss: PowerShell Conference EU – with 40 renown international speakers including PowerShell team members and MVPs, plus 350 professional and creative PowerShell scripters. Registration is open at www.psconf.eu, and the full 3-track 4-days agenda becomes available soon. Once a year it’s just a smart move to come together, update know-how, learn about security and mitigations, and bring home fresh ideas and authoritative guidance. We’d sure love to see and hear from you!

Twitter This Tip! ReTweet this Tip!

Using Localized User and Group Names

Here is a one-liner that returns the resolved name from the current user’s SID:

([System.Security.Principal.WindowsIdentity]::GetCurrent()).User.Translate( [System.Security.Principal.NTAccount]).Value

You may be arguing it is easier to query the environment variable $env:username for this, which is true. However, converting a SID to name can come handy in many scenarios. For example, if you must know the exact (localized) name for a well-known account or group, like the local Administrators group, simply use the language-neutral SID and have it translated:

 
PS> ([System.Security.Principal.SecurityIdentifier]'S-1-5-32-544').Translate( [System.Security.Principal.NTAccount]).Value

VORDEFINIERTAdministratoren 
 

Likewise, the line below always lists local Administrators, regardless of which language your operating system uses:

$admins = ([System.Security.Principal.SecurityIdentifier]'S-1-5-32-544').Translate( [System.Security.Principal.NTAccount]).Value
$parts = $admins -split '\'
$groupname = $parts[-1]

Get-LocalGroupMember -Group $groupname

psconf.eu – PowerShell Conference EU 2019 – June 4-7, Hannover Germany – visit www.psconf.eu There aren’t too many trainings around for experienced PowerShell scripters where you really still learn something new. But there’s one place you don’t want to miss: PowerShell Conference EU – with 40 renown international speakers including PowerShell team members and MVPs, plus 350 professional and creative PowerShell scripters. Registration is open at www.psconf.eu, and the full 3-track 4-days agenda becomes available soon. Once a year it’s just a smart move to come together, update know-how, learn about security and mitigations, and bring home fresh ideas and authoritative guidance. We’d sure love to see and hear from you!

Twitter This Tip! ReTweet this Tip!

SID of Current User

Here is a one-liner that returns the SID for the current user and can be used in logon scripts, for example:

([System.Security.Principal.WindowsIdentity]::GetCurrent()).User.Value

psconf.eu – PowerShell Conference EU 2019 – June 4-7, Hannover Germany – visit www.psconf.eu There aren’t too many trainings around for experienced PowerShell scripters where you really still learn something new. But there’s one place you don’t want to miss: PowerShell Conference EU – with 40 renown international speakers including PowerShell team members and MVPs, plus 350 professional and creative PowerShell scripters. Registration is open at www.psconf.eu, and the full 3-track 4-days agenda becomes available soon. Once a year it’s just a smart move to come together, update know-how, learn about security and mitigations, and bring home fresh ideas and authoritative guidance. We’d sure love to see and hear from you!

Twitter This Tip! ReTweet this Tip!