Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Windows Server Automation with PowerShell Cookbook, Fifth Edition

You're reading from   Windows Server Automation with PowerShell Cookbook, Fifth Edition Powerful ways to automate, manage, and administrate Windows Server 2022 using PowerShell 7.2

Arrow left icon
Product type Paperback
Published in Jan 2023
Publisher Packt
ISBN-13 9781804614235
Length 714 pages
Edition 5th Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Thomas Lee Thomas Lee
Author Profile Icon Thomas Lee
Thomas Lee
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Installing and Configuring PowerShell 7 FREE CHAPTER 2. Managing PowerShell 7 in the Enterprise 3. Exploring .NET 4. Managing Active Directory 5. Managing Networking 6. Implementing Enterprise Security 7. Managing Storage 8. Managing Shared Data 9. Managing Printing 10. Exploring Windows Containers 11. Managing Hyper-V 12. Debugging and Troubleshooting Windows Server 13. Managing Windows Server with Window Management Instrumentation (WMI) 14. Managing Windows Update Services 15. Other Books You May Enjoy
16. Index

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...

  1. Viewing the PowerShell version
    $PSVersionTable
    
  2. Viewing the $Host variable
    $Host
    
  3. Looking at the PowerShell process (PWSH)
    Get-Process -Id $PID |
      Format-Custom -Property MainModule -Depth 1
    
  4. Looking at resource usage statistics
    Get-Process -Id $PID |
      Format-List CPU,*Memory*
    
  5. 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
    
  6. Determining available commands
    Get-Command |
      Group-Object -Property CommandType
    
  7. 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.

You have been reading a chapter from
Windows Server Automation with PowerShell Cookbook, Fifth Edition - Fifth Edition
Published in: Jan 2023
Publisher: Packt
ISBN-13: 9781804614235
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime