Configuring Windows PowerShell, and finding and running commands

This lab should take approximately 60 minutes to complete.

Scenario

You’re an administrator who’ll use Windows PowerShell to automate many administrative tasks. You must ensure that you can successfully start the correct Windows PowerShell host applications and configure them for future use by customizing their appearance.

You’re also preparing to complete several administrative tasks by using Windows PowerShell. You need to discover commands that you’ll use to perform those tasks, run several commands to begin performing those tasks, and learn about new Windows PowerShell features that’ll enable you to complete those tasks.

Objectives

After completing this lab, you’ll be able to:

  • Open and configure the Windows PowerShell console application.
  • Open and configure the Windows PowerShell ISE application.
  • Find and run Windows PowerShell commands.
  • Use Windows PowerShell Help and About topics to learn new shell concepts and techniques.

Lab setup

Virtual machines: AZ-040T00A-LON-DC1 and AZ-040T00A-LON-CL1

User name: Adatum\Administrator

Password: Pa55w.rd

Lab startup

  1. Select LON-DC1.
  2. Sign in by using the following credentials:
    • User name: Administrator
    • Password: Pa55w.rd
    • Domain: Adatum
  3. Repeat these steps for LON-CL1.

Exercise 1: Configuring the Windows PowerShell console application

Exercise scenario 1

To customize Windows PowerShell, you need to first make changes to the console. In this exercise, you’ll open the Windows PowerShell console application and configure its appearance and layout.

The main tasks for this exercise are:

  1. Start the console application as Administrator, and pin the Windows PowerShell icon to the taskbar.
  2. Configure the Windows PowerShell console application.
  3. Start a shell transcript.

Task 1: Start the console application as Administrator, and pin the Windows PowerShell icon to the taskbar

  1. On LON-CL1, select Start.
  2. Enter powershell to display the Windows PowerShell icon. Make sure that the icon name displays Windows PowerShell and not Windows PowerShell (x86).
  3. Right-click Windows PowerShell or activate its context menu, and then select Run as administrator.
  4. Make sure that the window title bar reads Administrator and doesn’t include the text (x86). This indicates that it is the 64-bit console application and that an administrator is running it.
  5. On the taskbar, right-click the Windows PowerShell icon or activate its context menu, and then select Pin to taskbar. The Windows PowerShell console should now be open, run by Administrator, and available on the taskbar for future use.

Task 2: Configure the Windows PowerShell console application

  1. To configure Windows PowerShell to use the Consolas font:

    a. Select the control box in the upper-left corner of the Windows PowerShell console window.

    b. Select Properties.

    c. In the “Windows PowerShell” Properties dialog box, select the Font tab, and then, in the Font list, select Consolas.

    d. Select 16 in the Size list.

  2. To select alternate display colors, on the Colors tab, review the available Screen Text and Screen Background colors.

    Note: Experiment with various combinations. You can use the color picker to change colors quickly to improve readability.

  3. To resize the window and remove the horizontal scroll bar:

    a. On the Layout tab, in the Window Size settings, change the area’s Width and Height values until the Windows PowerShell console pane preview fits completely within the Window Preview area.

    b. On the Layout tab, in the Screen Buffer Size settings, change the Width value to be the same as the Width value in the Windows Size settings.

  4. Select OK. The console application should be ready for use.

Task 3: Start a shell transcript

  • In the Windows PowerShell console, enter the following command, and then press the Enter key:

     Start-Transcript C:\DayOne.txt
    

    Note: You’ve now started a transcript of your Windows PowerShell session. It’ll save all the commands you enter and the command output to the text file until you run Stop‑Transcript or close the Windows PowerShell window. You can review the contents of the transcript at any time by opening C:\DayOne.txt.

Exercise 1 results

After completing this exercise, you’ll have opened and configured the Windows PowerShell console application and configured its appearance and layout.

Exercise 2: Configuring the Windows PowerShell ISE application

Note: The Windows PowerShell ISE is available only for Windows PowerShell 5.1. It is no longer in active feature development and is not supported in PowerShell 7. Microsoft recommends Visual Studio Code with the PowerShell extension as the modern scripting environment. This exercise uses the ISE because it remains available on Windows 10/11 systems running Windows PowerShell 5.1.

Exercise scenario 2

In this exercise, you’ll customize the appearance of the Windows PowerShell ISE application.

The main tasks for this exercise are:

  1. Open the Windows PowerShell ISE application as Administrator.
  2. Customize the ISE’s appearance to use a single-pane view, hide the Command pane, and adjust the font size.

Task 1: Open the Windows PowerShell ISE application as Administrator

  1. In the Windows PowerShell console, enter ise, and then press the Enter key.

    Note: This method of opening the ISE will work correctly only when an administrator is running the console.

  2. Close the ISE window.

  3. Right-click the Windows PowerShell icon on the taskbar or activate its context menu, and then select Run ISE as Administrator. You should now be running Windows PowerShell ISE as Administrator.

Task 2: Customize the ISE’s appearance to use a single-pane view, hide the Command pane, and adjust the font size

  1. To configure the ISE to use the single-pane view:

    a. On the Windows PowerShell ISE toolbar, select the Show Script Pane Maximized option.

    b. Select the Hide Script Pane up-arrow icon to display the console.

    Note: Alternatively, you can press the Ctrl+R key combination.

  2. Select the Show Command Add-on option to review the Commands pane, if it isn’t showing.

  3. Select the Show Command Add-on option to hide the Commands pane.

  4. Use the slider in the lower-right corner of the window to adjust the font size until you can review it comfortably.

  5. Close the Windows PowerShell ISE and the Windows PowerShell windows.

Exercise 2 results

After completing this exercise, you’ll have customized the appearance of the Windows PowerShell Integrated Scripting Environment (ISE) application.

Exercise 3: Finding and running Windows PowerShell commands

Exercise scenario 3

In this exercise, you’ll use Windows PowerShell’s Get-Help and Get-Command commands to discover new commands that can complete specific tasks within Windows PowerShell. You’ll also run several basic Windows PowerShell commands. In some instances, you might have to find the commands that you’ll use to complete the task.

The main tasks for this exercise are:

  1. Find commands that’ll accomplish specified tasks.
  2. Run commands to accomplish specified tasks.

Task 1: Find commands that’ll accomplish specified tasks

  1. On LON-CL1, on the task bar, right‑click Windows PowerShell, and then select Run as Administrator.

  2. In the console, enter one of the following commands, and then press the Enter key:

    Get-Help *resolve* 
    

    or:

    Get-Command *resolve* 
    

    or:

    Get-Command -Verb resolve 
    

    Note: The first two commands display a list of commands that use Resolve anywhere in their names. The third displays a list of commands that use the verb Resolve in their name. All three will return the same results in the lab environment. This should lead you to the Resolve-DNSName command.

  3. In the console, enter one of the following commands, and then press the Enter key:

    Get-Help *adapter* 
    

    or:

    Get-Command *adapter* 
    

    or:

    Get-Command -Noun *adapter*
    

    or:

    Get-Command -Verb Set -Noun *adapter* 
    

    Note: The first three commands display a list of commands that use Adapter in their names. The fourth displays a list of commands that have Adapter in their names and use the Set verb. This should lead you to the Set-NetAdapter command.

  4. Run Get-Help Set-NetAdapter to review the help for that command. This should lead you to the ‑MACAddress parameter.

  5. In the console, enter one of the following commands, and then press the Enter key:

    Get-Help *sched* 
    

    or:

    Get-Command *sched* 
    

    or:

    Get-Module *sched* -ListAvailable
    

    Note: The first two commands display a list of commands that use Sched in their name. The third displays a list of modules with Sched in their name, which should lead you to the module ScheduledTasks. If you then run the command Get-Command -Module *ScheduledTasks*, you’ll get a list of commands in that module. This should lead you to the Enable-ScheduledTask command.

  6. In the console, enter one of the following commands, and then press the Enter key:

    Get-Command –Verb Block 
    

    or:

    Get-Help *block* 
    

    Note: These display a list of commands, which should lead you to the Block-SmbShareAccess command. Then, run Get-Help Block-SmbShareAccess to learn that the command applies a Deny entry to the file share discretionary access control list (DACL).

  7. In the console, enter the following command, and then press the Enter key:

    Get-Help *branch*
    

    Note: This will cause the help system to conduct a full-text search, because no commands use branch in their names.

    A list of topics containing the text branch displays, but none appear related to clearing the BranchCache cache.

  8. In the console, enter one of the following commands, and then press the Enter key:

    Get-Help *cache* 
    

    or:

    Get-Command *cache* 
    

    or:

    Get-Command -Verb clear
    

    Note: The first two commands will display a list of commands containing Cache in the name. The third displays a list of commands using the verb Clear in the name. Either way, you should discover the Clear-BCCache command.

  9. In the console, enter one of the following commands, and then press the Enter key:

    Get-Help *firewall*
    

    or:

    Get-Command *firewall* 
    

    or:

    Get-Help *rule*
    

    or:

    Get-Command *rule* 
    

    Note: These display a list of commands that use those words in their names, which should lead you to the Get-NetFirewallRule command.

  10. In the console, enter the following command, and then press the Enter key:

    Get-Help Get-NetFirewallRule –Full
    

    Note: This will display the help for the command, so you can discover the –Enabled parameter.

  11. In the console, enter the following command, and then press the Enter key:

    Get-Help *address* 
    

    Note: This will display a list of commands that use address in their names. This should lead you to the Get-NetIPAddress command.

  12. In the console, enter the following command, and then press the Enter key:

    Get-Command –Verb suspend
    

    Note: This displays a list of commands that use the verb Suspend in their names. This should lead you to the Suspend-PrintJob command.

  13. In the console, enter one of the following commands, and then press the Enter key:

    Get-Alias Type
    

    or:

    Get-Command –Noun *content* 
    

    Note: The first command displays the alias definition for the Type command, which is the command used in cmd.exe to review text from a file. The second command returns a list of commands with Content in the noun portion of the name. This should lead you to the Get-Content command.

Task 2: Run commands to accomplish specified tasks

  1. Ensure you are signed in on the LON-CL1 virtual machine as Adatum\Administrator.

  2. To display a list of enabled firewall rules, in the console, enter the following command, and then press the Enter key:

    Get-NetFirewallRule -Enabled True
    
  3. To display a list of all local IPv4 addresses, in the console, enter the following command, and then press the Enter key:

    Get-NetIPAddress –AddressFamily IPv4
    
  4. To set the startup type of the Background Intelligent Transfer Service (BITS), in the console, enter the following command, and then press the Enter key:

    Set-Service –Name BITS –StartupType Automatic 
    
  5. To test the connection to LON-DC1, in the console, enter the following command, and then press the Enter key:

    Test-Connection –ComputerName LON-DC1 –Quiet
    

    Note: This command returns only a True or False value, without any other output.

  6. To display the newest 10 entries from the Security event log, in the console, enter the following command, and then press the Enter key:

    Get-EventLog –LogName Security –Newest 10 
    

    Note: In PowerShell 7, use Get-WinEvent –LogName Security –MaxEvents 10 instead. The Get-EventLog cmdlet is only available in Windows PowerShell 5.1.

Exercise 3 results

After completing this exercise, you’ll have demonstrated your ability to find and run Windows PowerShell commands that perform specific tasks.

Exercise 4: Using About files

Exercise scenario 4

In this exercise, you’ll use help discovery techniques to find content in About files, and then use that content to answer questions about global Windows PowerShell functionality.

Remember that you must use Get-Help and wildcard characters. About files aren’t commands, Get-Command will not be useful in this exercise.

The main task for this exercise is:

  • Locate and review About help files.

Task 1: Locate and review About help files

  1. Ensure you’re still signed in to LON-CL1 as Adatum\Administrator from the previous exercise.

  2. To find operators used for wildcard string comparison, in the console, enter the following command, and then press the Enter key:

    Get-Help *comparison*
    
  3. In the console, enter the following command, and then press the Enter key:

    Get-Help about_comparison_operators -ShowWindow
    

    Notice the –Like operator in the about_Comparison_Operators Help, which displays in a modal window.

  4. To find the -Like operator, in the Find text box, enter wildcard, and then select Next.

  5. After reviewing the about_Comparison_Operators file, you should learn that typical operators are not case-sensitive. Specific case-sensitive operators are provided in about_Comparison_Operators.

  6. To display the COMPUTERNAME environment variable, in the console, enter the following command, and then press the Enter key:

    $env:computername
    

    You could learn about this technique in about_environment_variables.

  7. In the console, enter the following command, and then press the Enter key:

    Get-Help *signing*
    
  8. In the console, enter the following command, and then press the Enter key:

    Get-Help about_signing 
    
  9. Learn about code signing. You should learn that New-SelfSignedCertificate is used to create a self-signed digital certificate.

Exercise 4 results

After completing this exercise, you’ll have demonstrated your ability to locate help content in About files.