Install PowerShell 7
Powershell Core is intended to be the future of Powershell. It is intended to be multi-platform, supporting Windows, Linux and MacOS. At time of writing, I am on PowerShell 7.4.
I am working on a VM, so I create a folder called C:\PowerShell. I will copy these scripts to my OneDrive whenever I finish an exercise.
I add the line mkdir c:\PowerShell to my script and run it.
I save this script as 1. Setup.ps1
From this point onwards, ensure you save all your working scripts as I suggest, you will need to submit these later.
# Check the exising version
$PSVersiontable
# Set an execution policy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
# Install Nuget as a package provider
Install-PackageProvider Nuget -MinimumVersion 2.8.5.201 -Force | Out-Null
# Install the module
Install-Module -Name PowerShellGet -Force -AllowClobber
# Create a script directory
mkdir c:\PowerShell
Download PowerShell 7
Next, I open a new script window and save it as 2. Download PowerShell7.ps1
Microsoft have a generic script they make available, I past this into the new script window and save. I run the script, no errors.
# Download PowerShell 7 installation script
Set-Location C:\PowerShell
$URI = "https://aka.ms/install-powershell.ps1"
Invoke-RestMethod -Uri $URI |
Out-File -FilePath C:\PowerShell\Install-PowerShell.ps1
Check to make sure that script saved.
Install PowerShell 7
If I run the command Get-Help -Name C:\PowerShell\Install-PowerShell.ps1 I can see how the script can be used. My computer added some modules automatically when I used Get-Help.
I could run a very long command line, but there is a more elegant way to do this in PowerShell. I create a new script as 3. Install PowerShell 7 and set up the parameters in a variable and then pass then using @variable_name.

When I run the script, I note that everything downloads from GitHub!
Verifying Installation
The commands in PowerShell are sorted into modules. You can manually import modules of use autoload. If a module is called which has not been installed, PowerShell will fetch it.
In PowerShell, we define variables using a $ symbol. Try the command echo $env:PSModulePath The output is three separate paths, concatenated with a semicolon field separator. I create a new script window 4. Verify PowerShell 7
$I = 0
$env:PSModulePath -split ';' |
Foreach-Object {"[{0:N0}] {1}" -f $I++, $_}
What is this script doing?
First it sets the variable $I = 0,
Then it uses a split function to break up and pipes the output using the | symbol to a for-each loop.
The loop syntax will make more sense when we cover loops.
But now we know the locations of the modules PowerShell uses.
Close ISE, we will not be using it again for now. Open a command window and run PowerShell 7 by typing pwsh, then verify the version as we did before.

Last updated