PowerShell Exercises #3
PowerShell Exercises #3
Objective: Learn to navigate directories, list files, and create new directories using PowerShell.
Instructions:
1. Open PowerShell: Press the Windows key, type "powershell", and press Enter.
2. Get current directory: Type Get-Location and press Enter. This shows your current directory
3. List files and folders: Type Get-ChildItem and press Enter. This lists all files and folders in your
current directory. You can use Get-ChildItem -Force to also show hidden items.
4. Change directory: Use the Set-Location cmdlet to navigate to a different directory. For example,
5. Create a new directory: Use the New-Item cmdlet to create a new folder. For example, to create
Details:
Get-ChildItem: This cmdlet lists the files and folders in a specified location (or the current
Set-Location: This cmdlet changes the current working directory. You can provide a full path or a
New-Item: This cmdlet creates new items in the file system, such as files, directories, or registry
Internal
Only
Exercise 2: Working with Services
Objective: Learn to get information about services, start and stop services, and change service startup
types.
Instructions:
1. Open PowerShell: Press the Windows key, type "powershell", and press Enter.
2. List all services: Type Get-Service and press Enter. This displays a list of all services installed
3. Get a specific service: To get information about a specific service, use the -Name parameter.
For example, to get the status of the "Windows Audio" service, type:
PowerShell
Get-Service -Name "Audiosrv"
4. Start a service: To start a stopped service, use the Start-Service cmdlet. For example, to start
5. Stop a service: To stop a running service, use the Stop-Service cmdlet. For example, to stop the
6. Change startup type: To change how a service starts (e.g., Automatic, Manual, Disabled), use
the Set-Service cmdlet. For example, to set the "Windows Audio" service to start automatically,
type:
PowerShell
Set-Service -Name "Audiosrv" -StartupType 'Automatic'
Details:
Set-Service: This cmdlet modifies the configuration of a service, including its startup type.
Internal
Only
Exercise 3: Working with Variables and User Input
Objective: Learn to create variables, assign values to them, and get user input.
Instructions:
1. Open PowerShell: Press the Windows key, type "powershell", and press Enter.
2. Create a variable: To create a variable, use the $ symbol followed by a name. For example, to
3. Display the variable value: To display the value of a variable, simply type its name and press
Enter:
PowerShell
$username
4. Get user input: Use the Read-Host cmdlet to get input from the user. For example, to ask the
user for their name and store it in the $username variable, type:
PowerShell
$username = Read-Host "Please enter your name"
5. Use the variable in a command: You can use variables in commands. For example, to display a
Details:
Variables: Variables are used to store data in PowerShell. They are defined using the $ symbol.
Read-Host: This cmdlet prompts the user for input and returns the entered value.
Internal
Only