PowerShell for Windows Admins:

July, 2019


July 31, 2019  8:35 AM

Unblock and unzip

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

When you download a zip file from the Internet you have to unblock and unzip the file. I need to do this fairly often so wrote this simple function to perform both actions rather than doing it manually. function unzipfile { param ( [string]$path ) Unblock-File -Path $path Expand-Archive...

July 31, 2019  4:50 AM

Variables in scriptblocks

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

I often see questions regarding the use of variables in scriptblocks. Usually a variable will be defined outside the scriptblock and then an attempt will be made to use it in the scriptblock: PS> $path = 'C:\test\OldData01.txt' PS> Start-Job -Name j1 -ScriptBlock {Get-FileHash -Path $path...


July 29, 2019  12:59 PM

Test local user doesn’t exist before creating

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Saw a question asking how to Test local user doesn’t exist before creating. Windows 8 introduced the LocalAccounts module for Windows PowerShell. On Windows 10 1903 it runs in PowerShell v6/7. There isn’t a Test-Localuser cmdlet but you can attempt to get the user before...


July 28, 2019  5:31 AM

Missing verbs?

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

I saw a post that suggested that you can’t use Sort as a verb in your functions. You get a message that sort is an unapproved verb. Are there any other missing verbs? I started with the object cmdlets as they are probably the most used cmdlets. Running Get-Command *-Object...


July 27, 2019  12:00 PM

Sddl

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

An Sddl is a Security Descriptor Definition Language string - 0 Comments     RSS Feed     Email a friend


July 26, 2019  9:16 AM

Sort direction

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

By default Sort-Object uses an ascending sort direction. Get-Command | Sort-Object -Property Source will sort the commands based on the Source (module) in ascending Source order. If you use multiple properties Get-Command | Sort-Object -Property Source, Name, Version Your output is...


July 24, 2019  12:36 PM

Volume friendly name

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell

When you use Get-Volume one of the properties displayed is the volume friendly name PS> Get-Volume -DriveLetter C DriveLetter FriendlyName FileSystemType -----------     ------------         -------------- C                                             ...


July 23, 2019  4:03 AM

Using aliases in scripts

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

There’s been a long debate on the PowerShell github site regarding ternary operators – think of it as a short cut for if-else. Twice in that debate the point has been made that aliases are perfectly acceptable in scripts. Wrong. Using aliases in scripts should never be encouraged. Aliases...


July 22, 2019  1:15 PM

PowerShell v7 preview 2

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

PowerShell v7 preview 2 arrived a few days ago. No big ticket items in this preview. Some useful things: Issue with Get-ChildItem Path with wildcards has been fixed UseAbbreviationExpansion and TempDrive are moved from experimental features to official features Foreach-Object is 2...


July 16, 2019  12:02 PM

PowerShell v6.2.2

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

PowerShell v6.2.2 has just been released. One breaking change – the Enter-PSHostProcess is disabled when system is in lock down mode. The jumplist is now created in STA to avoid potential CLR crash Other changes are around the build process. These changes shouldn’t have impact on...


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: