Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to list all files in the current directory.
PowerShell
Get-ChildItem [1] Drag options to blanks, or click blank then click option'
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.✗ Incorrect
The -Path . option tells PowerShell to look in the current directory.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the folder name.
Using wrong folder name.
✗ Incorrect
The -Name 'Scripts' creates a folder named 'Scripts'.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping source and destination names.
Missing quotes around file names.
✗ Incorrect
The -Path must be the source file, which is 'file.txt'.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong file pattern like '*.csv'.
Using wrong destination folder name.
✗ Incorrect
'*.txt' selects all text files, and 'Archive' is the destination folder.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong filter pattern.
Mixing up dictionary keys.
✗ Incorrect
'*.log' filters log files, 'Name' and 'Size' are keys for file name and size.