Using the PowerShell 7 Console
Once you have installed PowerShell 7, you can explore the PowerShell 7 console irrespective of your installation method. In the main, the PowerShell 7 console is similar to the Windows PowerShell console, but you should notice a few differences.
Getting ready
You run this recipe on SRV1
after you have installed PowerShell 7. You can install PowerShell 7 using the installation script (as in the Installing PowerShell 7 recipe), Chocolatey (as in the Installing PowerShell 7 using Chocolatey recipe), or any other mechanism. You run this recipe in the PowerShell 7 console – pwsh.exe
.
How to do it...
- Viewing the PowerShell version
$PSVersionTable
- Viewing the
$Host
variable$Host
- Looking at the PowerShell process (
PWSH
)Get-Process -Id $PID | Format-Custom -Property MainModule -Depth 1
- Looking at resource usage statistics
Get-Process -Id $PID | Format-List CPU,*Memory*
- Updating the PowerShell 7 help files
$Before = Get-Help -Name about_* Update-Help -Force | Out-Null $After = Get-Help -Name about_* $Delta = $After.Count - $Before.Count "{0} Conceptual Help Files Added" -f $Delta
- Determining available commands
Get-Command | Group-Object -Property CommandType
- Examining the Path Variable
$env:path.split(';')
How it works...
In step 1, you view the PowerShell version information contained in $PSVersionTable
, which produces output like this:
Figure 1.12: Viewing the $PSVersionTable variable
In step 2, you view the contents of the $Host
variable, which contains details of the PowerShell host (i.e., the PowerShell 7 console), which looks like this:
Figure 1.13: Viewing $Host
In step 3, you view the details of the PowerShell process (pwsh.exe
) with output like this:
Figure 1.14: Viewing the pwsh process
In step 4, you can observe the resources used by this process by using Get-Process
and viewing the resource-related properties, with output like this:
Figure 1.15: Viewing the pwsh resource usage
It is always useful to get the most up-to-date help files, which you can do using Update-Help
. In step 5, you update the PowerShell 7 help files and count the number of conceptual help files resulting from updating help. The output of this step looks like this:
Figure 1.16: Updating the PowerShell 7 help files
In step 6, you use Get-Command
to determine the number of commands available to a newly installed version of PowerShell 7.2.2 (in this case!) on a freshly installed version of Windows Server 2022. The output looks like this:
Figure 1.17: Updating the PowerShell 7 help files
In the final step, step 7, you review the contents of the path
environment variable, with output like this:
Figure 1.18: Viewing the available commands in PowerShell 7
There’s more...
In step 1, you examine the $PSVersion
built-in variable. At the time of writing, the latest released version of PowerShell 7 is 7.2.2, as you can see in the output. However, when you run this step, you may discover you have installed a later version.
You run pwsh.exe
to start PowerShell 7 via the console. PowerShell has a built-in variable, $PID
, which holds the Windows process ID for the current PowerShell console. This variable can be useful if you have multiple consoles open at one time. You can use Get-Process
, as shown in step 2, specifying the process ID, to get details of this PowerShell process.