Five PowerShell cmdlets for Beginners
For years, Windows PowerShell has been the scripting language of choice for Microsoft IT professionals, and for good reason. The strength of PowerShell over other languages is the simplicity and readability that allows novice scripters and programmers learn it quickly. By default, in new Windows operating systems (currently Windows 10 and Windows Server 2019), installed right out of the box, there are thousands of cmdlets in PowerShell to use. In essence, these cmdlets can do just about anything on a Windows computer that might be done through a graphical user interface.
The sheer number can sometimes make it difficult for beginners to figure out where to start. Of course, there are cmdlets that are used quite frequently, not to mention cmdlets to make learning PowerShell easier.
PowerShell cmdlets (commands) are specialized classes within .NET. One of the more confusing aspects of PowerShell that users of other languages must understand is that in PowerShell, everything is an object and these objects have properties (properties are data about an object, such as a file name) and methods (operations that can be done to objects, such as deleting a file). You can’t really use or think of PowerShell as the “Bash for Windows” because PowerShell doesn’t work the same way as Bash. PowerShell structures much of the input data as objects automatically, unlike Bash, which uses text streams.
Get-Help
The Get-Help cmdlet is perhaps PowerShell’s most valuable cmdlet as it allows a user to see what a specific cmdlet does, the parameters the cmdlet is used with, and best of all, gives examples of how the cmdlet is used. You can think of it as similar to the man command on Linux. Even better, Get-Help displays information other than just the cmdlets, and you can learn about things such as operators and language concepts.
In this first example, the –Name parameter is used to display help on the Add-Contentcmdlet. In addition, the –Full parameter is used to show the entire help page on this topic, which includes a synopsis, parameter explanations, and examples.
PS C:\> Get-Help -Name Add-Content -Full NAME Add-Content SYNOPSIS Appends content, such as words or data, to a file.
For many developers, simply viewing examples of how a cmdlet is used is sufficient, so instead of specifying –Full, the –Examples parameter can be used as seen in Figure 1.
An often-overlooked aspect of Get-Help is the ability to view information on concepts in PowerShell. To view these topics in Get-Help, the concept is prefixed with about_. For instance, to view information on the concept of comparison operators, the PowerShell command would be about_Comparison_Operators.
A bit number challenged? The title would typically denote this post contains more than one.
It’s an excerpt. Click the ‘Read More” link at the bottom.