Introduction

What is PowerShell?

Windows PowerShell is a command-line shell and scripting language designed especially for system administration. Built on the .NET Framework and/or .NET Core , Windows PowerShell helps ICT professionals to control and automate the administration of the Windows operating system and applications that run on Windows Server environment. There is something similar in Linux called as Bash Scripting.

Windows PowerShell commands, called cmdlets, let you manage the computers from the command line. Windows PowerShell providers let you access data stores, such as the Registry and Certificate Store, as easily as you access the file system.

In addition, Windows PowerShell has a rich expression parser and a fully developed scripting language. So in simple words you can complete all the tasks that you do with GUI and much more.

Where to use PowerShell?

In the beginning PowerShell ws associated with the Windows operating system’s administration task. It is a scripting language and associated with Windows OS. Now it is eventually available also as an open-source utility. PowerShell provides access to COM and WMI, enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and CIM enabling management of remote Linux systems and network devices. Also Microsoft Azure cloud services can be managed with PowerShell. It has a set of cmdlets for managing Azure resources directly from the PowerShell command line.

PowerShell is designed to make it easy to learn and get started with, but provides powerful features for automation. It is a useful utility for Windows administrators to automate the repetitive task through scripting to increase efficiency. It is a command-line utility that supports the PowerShell scripts. It also supports a GUI based interface which is known as PowerShell ISE or Integrated Scripting Environment.

It supports several native commands that can interact and controlled by Batch script in the Windows Operating system. Some of the basic uses of PowerShell scripts are installing and uninstalling Windows Applications, Finding the IP addresses, printing the list of running resources and counting the list of files and folders.

Take a look Power of PowerShell

PowerShell Console

Typically PowerShell is run in a console. PowerShell is a task based command line shell and scripting language. PowerShell provides an interactive command-line interface, where the commands can be entered and their output displayed. The user interface offers customizable tab completion.

Windows

To run it, click Start, type PowerShell. Powershell

To run PowerShell7, click Start, type PowerShell7. Powershell7

MacOS

You can use PowerShell also in MacOS. Install PowerShell on MacOs

To run PowerShell, start it from Finder or from Menu Bar. Powershell in Mac PowerShell runs in a pwsh-console. Powershell Console in Mac

PowerShell ISE

The Windows PowerShell Integrated Scripting Environment (ISE) is a host application for Windows PowerShell. In Windows PowerShell ISE, you can run commands and write, test, and debug scripts in a single Windows-based graphic user interface with multiline editing, tab completion, syntax coloring, selective execution, context-sensitive help, and support for right-to-left languages.

PowerShell ISE

You can use menu items and keyboard shortcuts to perform many of the same tasks that you would perform in the Windows PowerShell console. For example, when you debug a script in the Windows PowerShell ISE, to set a line breakpoint in a script, right-click the line of code, and then click Toggle Breakpoint.

PowerShell four named commands

Windows PowerShell can execute four kinds of named commands:
- cmdlets
- PowerShell scripts, files suffixed by .ps1
- PowerShell functions
- standalone executable programs.

If a command is a standalone executable program, PowerShell launches it in a separate process. If it is a cmdlet, it executes in the PowerShell process. PowerShell enables the creation of aliases for cmdlets, which PowerShell textually translates into invocations of the original commands.

PowerShell supports both named and positional parameters for commands. In executing a cmdlet, the job of binding the argument value to the parameter is done by PowerShell itself, but for external executables, arguments are parsed by the external executable independently of PowerShell interpretation.

Cmdlet

A cmdlet (pronounced "command let") is a lightweight command used in the Windows PowerShell environment. Cmdlets are .NET Framework programs designed to interact with PowerShell.

Cmdlet vs Command

Cmdlets are way different from commands in other command-shell environments in the following manners: - Cmdlets are .NET Framework class objects - not just stand-alone executables. - Cmdlets can be easily constructed from as few as a dozen lines of code. - Parsing, error presentation, and output formatting are not handled by cmdlets. It is done by the Windows PowerShell runtime. - Cmdlets process works on objects not on text stream and objects can be passed as output for pipelining. - Cmdlets are record-based as they process a single object at a time.

Number of commands are different in different environments

PowerShell can be used also in Macos and Linux. There is anyway different amount of commands. For example we can check how many commands starting with verb Get we have in our Powershell with the following command.

Get-Command -Name get* | Measure-Object

The result in Windows 10 was 411, and please note that the result in Macos gives 62. Get -commands

Briefly

PowerShell is a task based command line shell and scripting language. To run it, click Start, type PowerShell, run PowerShell ISE or PowerShell as Administrator. Commands are written in verb-noun form, and named parameters start with a dash.

Essential terms

Term Meaning
Cmdlet Commands built into shell written in .NET
Functions Commands written in PowerShell language
Parameter Argument to a Cmdlet/Function/Script
Alias Shortcut for a Cmdlet or Function
Scripts Text files with .ps1 extension
Applications Existing windows programs
Pipelines The output of one command can be used as input for another command
Workflow a special kind of function that executes cmdlets or other functions in a specific, defined order