Skip to main content

🐚 PowerShell

  • 3 hours
  • In teams of 3 to 4 people

🎯 Learning Objective​

  • Learn the basic syntax of PowerShell.
  • Understand how to execute commands and scripts.

📜 Statement​

PowerShell is a command-line shell developed by Microsoft, which allows for task automation and system configuration management. It is more powerful than the classic command prompt (CMD) and offers a rich syntax for manipulating objects. In this exercise, you will discover the basic commands of PowerShell and how to use them to interact with the system.

You will first work individually, then share your work to discuss your findings. I suggest taking 1.5 to 2 hours for individual work, then dedicating the remaining time to sharing.

info

Your team submits a folder containing a powershell.md file and the scripts on Omnivox. The powershell.md file must include the names of the team members.

Step 1: Know PowerShell​

Write an introduction to PowerShell, explaining what it is, its main features, and how it compares to the command prompt (CMD). For example, here are some questions to guide you:

  • Does PowerShell work with objects or strings?
  • What is the basic syntax for executing a command?
  • Commands often start with a verb followed by a noun. Why?
  • How do you get help on a command?
  • How do you pass parameters to a command?
  • How do you declare a variable?
  • What is an alias?
  • How do you access an object's properties?
  • How do you access an object's methods?
  • What is the current version of PowerShell?
  • Is PowerShell cross-platform?
  • What are the differences between PowerShell Core and Windows PowerShell?

Step 2: PowerShell Script​

Write an introduction to PowerShell scripts, explaining how to write a script, how to save it, and how to execute it. For example, here are some questions to guide you:

  • What is the extension of a PowerShell script?
  • How do you execute a PowerShell script?
  • How do you declare a variable in a script?
  • How do you access the parameters of a script?
  • How do you use loops and conditions in a script?
  • How do you use functions in a script?

Step 3: Practical Exercise 1​

Write a script to inventory your system. The script should do the following:

  • Display the computer name.
  • Display the current user's name.
  • Display the PowerShell version.
  • Display the Windows version.
  • Display the list of hardware (processor, memory, hard drive, graphics card, etc.).

Step 4: Practical Exercise 2​

It is possible to modify the behavior of PowerShell at startup by using a profile file. You must:

  1. Find out which profile file is used by your version of PowerShell
  2. Research the different customization options available
  3. Create a profile file to customize your PowerShell environment

For example, you can change how PowerShell displays the current folder to, for example, show only the name of the current folder without the full path.