0
0
PowerShellscripting~10 mins

PowerShell on Linux - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to display the current directory in PowerShell on Linux.

PowerShell
Get-Location | Select-Object -ExpandProperty [1]
Drag options to blanks, or click blank then click option'
APath
BName
CLength
DMode
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'Name' which only shows the folder name, not full path.
Using 'Length' or 'Mode' which are unrelated properties.
2fill in blank
medium

Complete the code to list all files in the current directory on Linux using PowerShell.

PowerShell
Get-ChildItem -File | Where-Object [1] { $_.Length -gt 0 }
Drag options to blanks, or click blank then click option'
A-Property
B-FilterScript
C-Filter
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-Filter' which is a parameter for Get-ChildItem, not Where-Object.
Using '-Property' which is not valid for Where-Object.
3fill in blank
hard

Fix the error in the code to create a new directory named 'TestDir' on Linux using PowerShell.

PowerShell
New-Item -ItemType Directory -Name [1]
Drag options to blanks, or click blank then click option'
A'TestDir'
B-TestDir
CTestDir
D/TestDir
Attempts:
3 left
💡 Hint
Common Mistakes
Including quotes around the directory name.
Using a path starting with '/' which is not needed here.
4fill in blank
hard

Fill both blanks to read the content of a file named 'log.txt' and display only lines containing 'error'.

PowerShell
Get-Content [1] | Where-Object { $_ [2] 'error' }
Drag options to blanks, or click blank then click option'
Alog.txt
B-like
C-match
Dlog
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-like' which is for wildcard matching, not regex.
Using 'log' instead of the full file name.
5fill in blank
hard

Fill all three blanks to create a hashtable with file names as keys and their sizes as values for files larger than 1KB.

PowerShell
$files = Get-ChildItem -File | Where-Object { $_.Length [1] 1024 }
$sizes = @{}
foreach ($file in $files) { $sizes[[2]] = [3] }
Drag options to blanks, or click blank then click option'
A>
B$file.Name
C$file.Length
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causing wrong files to be selected.
Swapping keys and values in the hashtable.