0
0
PowerShellscripting~10 mins

PowerShell on macOS - 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 path in PowerShell on macOS.

PowerShell
Get-Location | Select-Object -ExpandProperty [1]
Drag options to blanks, or click blank then click option'
APath
BName
CFullName
DDirectory
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Name' or 'FullName' which do not exist on the object returned by Get-Location.
Using 'Directory' which is not a property of the location object.
2fill in blank
medium

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

PowerShell
Get-ChildItem -File | [1] Name
Drag options to blanks, or click blank then click option'
ASort-Object
BSelect-Object
CWhere-Object
DMeasure-Object
Attempts:
3 left
💡 Hint
Common Mistakes
Using Where-Object which filters items but does not select properties.
Using Sort-Object which sorts but does not select properties.
3fill in blank
hard

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

PowerShell
New-Item -ItemType Directory -Name [1]
Drag options to blanks, or click blank then click option'
ATestFolder
B'TestFolder'
C-TestFolder
D/TestFolder
Attempts:
3 left
💡 Hint
Common Mistakes
Including quotes inside the blank which causes the name to be a string literal with quotes.
Using a path format like '/TestFolder' which is not needed here.
4fill in blank
hard

Fill both blanks to filter files larger than 1MB and display their names in PowerShell on macOS.

PowerShell
Get-ChildItem -File | Where-Object { $_.[1] [2] 1MB } | Select-Object Name
Drag options to blanks, or click blank then click option'
ALength
B>
C<
DSize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Size' which is not a property of file objects in PowerShell.
Using '<' instead of '>' which filters smaller files.
5fill in blank
hard

Fill all three blanks to create a hashtable of file names and their sizes for files modified in the last 7 days on macOS PowerShell.

PowerShell
$recentFiles = @(); foreach ([2] in (Get-ChildItem -File | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) })) { $recentFiles += @{ [1] = $[2].Name; [3] = $[2].Length } }
Drag options to blanks, or click blank then click option'
AName
Bfile
CSize
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names in the loop and hashtable.
Using 'Length' as a key instead of 'Size'.