0
0
PowerShellscripting~10 mins

Why automation saves time 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 display the current date and time.

PowerShell
Get-Date | [1]
Drag options to blanks, or click blank then click option'
AStart-Process
BWrite-Output
COut-File
DGet-Content
Attempts:
3 left
💡 Hint
Common Mistakes
Using Out-File writes to a file, not the screen.
Using Start-Process starts a new process, not output.
Using Get-Content reads from a file, not output.
2fill in blank
medium

Complete the code to create a folder named 'Reports'.

PowerShell
New-Item -Path . -Name 'Reports' -ItemType [1]
Drag options to blanks, or click blank then click option'
ADirectory
BFile
CText
DProcess
Attempts:
3 left
💡 Hint
Common Mistakes
Using File creates a file, not a folder.
Using Text is not a valid item type here.
Using Process is unrelated to creating folders.
3fill in blank
hard

Fix the error in the script to list all files in the current directory.

PowerShell
Get-ChildItem [1]
Drag options to blanks, or click blank then click option'
A-Content
B-Folder
C-Process
D-File
Attempts:
3 left
💡 Hint
Common Mistakes
Using -Folder lists folders, not files.
Using -Process is invalid here.
Using -Content is not a valid parameter for this cmdlet.
4fill in blank
hard

Fill both blanks to create a loop that prints numbers 1 to 5.

PowerShell
for ($i = [1]; $i [2] 5; $i++) { Write-Output $i }
Drag options to blanks, or click blank then click option'
A1
B<=
C<
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 0 prints 0 which is not needed here.
Using < instead of <= misses printing 5.
5fill in blank
hard

Fill all three blanks to create a hashtable of file sizes for '.txt' files.

PowerShell
$sizes = @{}; foreach ([3] in Get-ChildItem -Filter '*.txt') { $sizes[[1]] = [2].Length }
Drag options to blanks, or click blank then click option'
A$file.Name
B$file
D$item
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names causes errors.
Using $item instead of $file breaks the loop variable.