0
0
PowerShellscripting~10 mins

Why file management is core to scripting in PowerShell - Test Your Understanding

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

Complete the code to list all files in the current directory.

PowerShell
Get-ChildItem [1]
Drag options to blanks, or click blank then click option'
A-Path .
B-File
C-Recurse
D-Name
Attempts:
3 left
💡 Hint
Common Mistakes
Using -File alone lists only files, but no path specified.
Using -Recurse lists files in all subfolders, not just current.
2fill in blank
medium

Complete the code to create a new folder named 'Scripts'.

PowerShell
New-Item -ItemType Directory -Name [1]
Drag options to blanks, or click blank then click option'
A'Files'
B'Scripts'
C'Documents'
D'Data'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the folder name.
Using wrong folder name.
3fill in blank
hard

Fix the error in the code to copy 'file.txt' to 'backup.txt'.

PowerShell
Copy-Item -Path [1] -Destination 'backup.txt'
Drag options to blanks, or click blank then click option'
A'file.txt'
B'file_backup.txt'
C'backup.txt'
D'file'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping source and destination names.
Missing quotes around file names.
4fill in blank
hard

Fill both blanks to move all '.txt' files to the 'Archive' folder.

PowerShell
Move-Item -Path [1] -Destination [2]
Drag options to blanks, or click blank then click option'
A'*.txt'
B'*.csv'
C'Archive'
D'Backup'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong file pattern like '*.csv'.
Using wrong destination folder name.
5fill in blank
hard

Fill all three blanks to create a dictionary of file names and their sizes for '.log' files.

PowerShell
$files = Get-ChildItem -Filter [1] | ForEach-Object { @{ [2] = $_.Name; [3] = $_.Length } }
Drag options to blanks, or click blank then click option'
A'*.log'
B'Name'
C'Size'
D'*.txt'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong filter pattern.
Mixing up dictionary keys.