PowerShell: Installation

What is PowerShell?

PowerShell is a command-line shell and scripting language typically used to automate tasks and perform configuration management on local and remote computers. It is commonly used by System Administrators. Precursors to PowerShell were Windows batch files and Windows Script Host used in DOS and Windows 98, as well as Microsoft Monad. As of August 2016, PowerShell became open-source and cross-platform with support for Windows, macOS, CentOS and Ubuntu.

Windows PowerShell can execute four kinds of named commands:

  • cmdlets - .NET Framework programs designed to interact with PowerShell
  • PowerShell scripts - files suffixed by .ps1
  • PowerShell functions
  • Standalone executable programs

How to Run a PowerShell script

In order to run your PowerShell scripts in Windows, you will need to change the execution policy in PowerShell to allow scripts to run. To do this, go to the Windows Command prompt by clicking Start and typing CMD, open up PowerShell by typing 'powershell', and then type the following command:

Set-ExecutionPolicy RemoteSigned

screenshot of PowerShell Set-ExecutionPolicy RemoteSigned


Example: Simple Output in PowerShell


	Write-Host "Hello, World!"
	

Output:

  Hello, World!


If you have a script named hello.ps1 stored in the root folder of your d: drive, you can then run your PowerShell script by typing the following command in the PowerShell console.

& "d:\hello.ps1"

screenshot of PowerShell Set-ExecutionPolicy RemoteSigned