0
0
PowerShellscripting~10 mins

Platform-specific considerations in PowerShell - Interactive Code Practice

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

Complete the code to get the current user's home directory in PowerShell.

PowerShell
Write-Output $[1]
Drag options to blanks, or click blank then click option'
AHOME
B$env:USERPROFILE
Cenv:PATH
DUSER
Attempts:
3 left
💡 Hint
Common Mistakes
Using $HOME which is common in Linux but not in Windows PowerShell.
Using $USER which is not defined in PowerShell.
2fill in blank
medium

Complete the code to check if the current OS is Windows in PowerShell.

PowerShell
if ($PSVersionTable.OS -[1] 'Windows') { Write-Output 'Windows OS' }
Drag options to blanks, or click blank then click option'
A-match
B-eq
C-like
D-contains
Attempts:
3 left
💡 Hint
Common Mistakes
Using -eq which requires exact match.
Using -contains which is for collections, not strings.
3fill in blank
hard

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

PowerShell
Get-ChildItem -Path . | Where-Object { $_.[1] -eq $false }
Drag options to blanks, or click blank then click option'
APSIsContainer
BType
CMode
DFileType
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Type' or 'Mode' which do not directly indicate file or folder.
Checking for 'File' string which is not a property value.
4fill in blank
hard

Fill both blanks to create a dictionary of file names and sizes for files larger than 1MB in the current directory.

PowerShell
$files = @{ } ; Get-ChildItem -File | Where-Object { $_.Length [1] 1MB } | ForEach-Object { $files[[2]] = $_.Length }
Drag options to blanks, or click blank then click option'
A>
BName
CLength
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > for size comparison.
Using Length as dictionary key instead of Name.
5fill in blank
hard

Fill all three blanks to create a list of process names running with more than 100 MB memory usage.

PowerShell
$heavyProcs = Get-Process | Where-Object { $_.[1] [2] 100MB } | Select-Object -ExpandProperty [3]
Drag options to blanks, or click blank then click option'
AWorkingSet64
B>
CProcessName
DId
Attempts:
3 left
💡 Hint
Common Mistakes
Using Id instead of ProcessName for output.
Using < instead of > for filtering memory usage.