PowerShell 7: Download, Install, Update And Usage Guide

The Windows PowerShell is an automation engine based on .NET Common Language Runtime. It is designed to help system administrators with complex and time-consuming tasks that will, if done manually, cause many human errors or consume a lot of time.

It provides sysadmins the ability to automate various tasks across platforms and as it allows admins complete access to COM and WMI, both local and remote systems can be managed with PowerShell. It comes with its own scripting language and special .NET classes called cmdlets used for specific functions.

These cmdlets are usually utilized by scripts that are themselves packaged into modules. Here, we will guide you through the complete process of downloading, installing, updating, and using PowerShell 7 for Windows 10.

Download PowerShell 7

If you want to download and install PowerShell 7, follow the following simple steps.

  1. Visit PowerShell Github repository.
  2. Click on the Assets section to expand it. 
  3. Select a version of PowerShell that is in accordance with your Windows architecture. The two versions are the PowerShell-7.x.x-win-x64.msi and PowerShell-7.x.x-win-x86.msi.

Install PowerShell 7

Install PowerShell 7 manually using the downloaded installation files

PowerShell 7
PowerShell 7

Run the package and follow the simple prompts for destination of installation and optional Actions such as enabling “Open Here” to explorer menus.

PowerShell 7 optional actions
PowerShell 7 optional actions

If you have PowerShell core 6.x already installed on the system, version 7 will be installed as an update, essentially removing the core 6.x.

PowerShell 5.1 is not removed, and PowerShell 7 runs separately. 

The default destination for the install is $env:ProgramFiles\PowerShell\<version>. You can run it from the Start Menu or directly from the directory. The executable is named pwsh.exe.

To run PowerShell 5, go to Run –> powershell

To run PowerShell 7, go to Run –> pwsh

Installing PowerShell 7 using command-line

To install PowerShell 7 automatically with the default options, go to Run –> powershell. Now run the following command:

iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Quiet"
Install PowerShell using command line
Install PowerShell using command line

This will automatically download and install the latest version of PowerShell with default options.

Installing PowerShell 7 over the network

If you want to install PowerShell 7 as a sysadmin on all machines under your control, follow these simple steps.

  1. Download and copy the .msi file in the file share. Make sure all machines have access to this shared path.
  2. On the Active Directory server, open the Group Policy Management Console. 
  3. Open the GPO where you want to implement this PowerShell 7 installation configuration. Then, go to Computer Configuration –> Software Settings
  4. Right Click on Software Installation and click New and then Package. In the dialogue box add the .msi file path. Include the complete path, for example \\server.name\foldername\PowerShell-7.x.x-win-x64.msi
  5. Select Open, followed by Assigned, and click OK to create. 
  6. Attach it to the OU and wait until deployment is complete.  

Using PowerShell 7 

By default, you may be restricted from running custom PowerShell single function commands, most commonly referred to as cmdlets. You will have to change the execution policy in order to run custom command-lets. Follow these simple steps to do so. 

  1. Run PowerShell as an administrator. 
  2. Run the following commands.
    1. Get-ExecutionPolicy
    1. Set-executionpolicy unrestricted
  3. Enter Y in the prompt
  4. Get-ExecutionPolicy 

PowerShell 7 is designed for object-oriented use, so it is much easier than other similar engines. It uses small, lightweight, single-function commands, mostly written in C# called cmdlets that perform a specified function and return a .NET object. PowerShell has around 200 cmdlets, that can be accessed using the command “PS C:\> Get-Command”, however, the most commonly used are:

  • Get-Location: Gets current directory
  • Set-Location: Gets current directory
  • Move-item: Moves file to new destination
  • Copy-item: Copies file to new destination
  • Rename: Renames existing file
  • New-item: Creates new file

You can give specific instructions to the cmdlets using the following: 

  • What if: The cmdlet will show what it will do if executed, without running. 
  • Confirm: The cmdlet will confirm before executing
  • Verbose: Increased detail.       
  • Debug: The cmdlet will display debugging information.
  • ErrorAction: Determines what to do when an error occurs and has four actions: continue, stop, silently- continue, and inquire.
  • ErrorVariable: Determines which variable will hold error information.
  • OutVariable: Determines which variable will hold output information.
  • OutBuffer: the cmdlet will not call the next cmdlet until it holds a certain preset number of objects.

PowerShell uses the following special variables. 

  • $Error: An array of error objects, used to display recent errors
  • $Host: Display what current hosting application is
  • $Profile: Store entire path of a user profile
  • $PID: Store process identifier
  • $PSUICulture: Used to hold the name of current UI culture.
  • $NULL: Contains NULL value.
  • $False: Contains FALSE value
  • $True: Contains TRUE value

An important concept of the PowerShell script is the pipe character. It is used to separate two commands. The command or group of commands on the left of the pipe are executed first and then forwarded to the command or group of commands to the right of the pipe. This allows the creation of so-called pipeline commands. These are long commands that may or may not occur in a single physical line, but for all intents and purposes function as a single line of code. 

If you want to run a script in PowerShell you will need to use ISE. PowerShell ISE (Integrated Scripting Environment) is the built-in editor for PowerShell. It can be used to run, test, and debug scripts, all in a window-based GUI setting. It has all the features of GUI editing and allows multiline editing, tab completion, and a host of other things like executing commands in the console pane.

In Windows 10, you can even open more than one script window and work on them at the same time. This comes in handy when a script that uses functions that have been defined in separate modules needs to be debugged. 

All in all, the PowerShell 7 for Windows 10 is an easy to use admin tool that all sysadmins should be able to use with minimal training. 

 

Continue Reading:

Join 6000+ other users and have new posts emailed to you

Discover new tech tips and troubleshooting guides as soon as they are published

Leave a Comment