Microsoft has invested a lot of time to add numerous features to Windows PowerShell version 5. Some of the more...
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
prominent features in PowerShell 5 such as classes, the PowerShellGet module, the PackageManagement module and the new Write-Information cmdlet have gotten a lot of attention.
However, there were dozens of other useful updates to PowerShell that got lost in the buzz of the big updates. Here are four new PowerShell 5 features I believe should be getting more coverage.
A better file management cmdlet
Lee Holmes, senior software developer engineer for PowerShell at Microsoft, built a popular script years ago called Send-File.ps1 that sends files over PowerShell remoting sessions. The script is useful because it does not require Server Message Block to get a file from point A to point B.
Using that script, administrators didn't worry about opening up another port on the firewall. File copies could then use the PowerShell remoting TCP port. Microsoft decided to bring this functionality into the native codebase by implementing this functionality on the Copy-Item cmdlet using the ToSession parameter.
In Figure 1, the example shows how to establish a new PowerShell session to a remote computer, specify the source of a local file, the destination and the session to use. No external script necessary.
Native .zip support added
In the previous version of PowerShell, there was no native function to create and expand .zip files. You were forced to scour the Internet for scripts to do this. PowerShell version 5 makes working with .zip files more convenient because this support is built right into the language with the Microsoft.PowerShell.Archive module. This module contains a cmdlet to create .zip files called Compress-Archive and a cmdlet to unzip or expand .zip files called Expand-Archive.
In Figure 2, you can see it's possible to gather a list of files in a folder then pass this to Compress-Archive to create a .zip file. Conversely, you can pass the .zip file to Expand-Archive which will expand the contents.
Native symbolic link support
The bash shell in Linux has the ability to create file system symbolic links for quite a while. Although this was technically possible in previous versions of PowerShell by developing code in .NET or by using command-line utilities such as mklink.exe, it is now a native feature in PowerShell version 5.
By adding a single parameter argument to the ItemType parameter of the New-Item cmdlet you can natively create symbolic links without the use of any external command-line utilities or .NET code.
In Figure 3, we create a symbolic link called MySymLinkFile.txt in the C:\Windows\Temp folder that is linked to the text.txt file in the current directory. Notice the Mode property and the last attribute letter "l" that signifies a symbolic link.
Limiting folder depth with Get-ChildItem
PowerShell has long had the Get-ChildItem cmdlet to list various items presented by providers. Using Get-ChildItem to list files and folders on the file system or registry keys in the registry are some of the popular uses of this cmdlet. The file system and registry both store information in a hierarchical form through folders or registry keys.
Sys admins could use the -Recurse parameter to find items stored in subfolders or keys; this parameter could "walk" the hierarchy of items to list all subfolders or registry keys. But limiting the depth of the hierarchy was always a challenge. Microsoft developed the –Depth parameter for Get-ChildItem to make this task easier.
Let's say we have a folder structure that is five levels deep; using Get-ChildItem with the –Recurse parameter I can list each of these folders. But if, in Figure 4, I want to see all the folders just two levels deep, I can specify this by using the –Depth parameter and the amount I want to see.
These are just four of the many useful updates to PowerShell 5. To see the entire list of new features, check out the What's New in PowerShell Technet article where Microsoft details the new updates and features.
How to deconstruct strings with PowerShell 5
Remote file editing and other PowerShell 5 improvements
Three advantages to using PowerShell Desired State Configuration