Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to run a command remotely on a computer named 'Server01'.
PowerShell
Invoke-Command -ComputerName Server01 -ScriptBlock { Get-Process } -Credential [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable that does not contain credentials causes authentication errors.
Omitting the -Credential parameter leads to permission denied errors.
✗ Incorrect
You need to provide the user credentials to run commands remotely. $UserCredential holds these credentials.
2fill in blank
mediumComplete the code to create a persistent remote session to 'Server02'.
PowerShell
$session = New-PSSession -ComputerName Server02 -Credential [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable without credentials causes session creation to fail.
Confusing session variables with credential variables.
✗ Incorrect
New-PSSession requires credentials to establish a remote session. $AdminCreds holds the admin credentials.
3fill in blank
hardFix the error in the code to run a script block on multiple computers stored in $computers.
PowerShell
Invoke-Command -ComputerName [1] -ScriptBlock { Get-Service } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a singular variable name when the list is plural.
Omitting the $ sign for variables.
✗ Incorrect
The variable holding multiple computer names is $computers. Using $computer (singular) or unprefixed names causes errors.
4fill in blank
hardFill both blanks to filter services running on remote computers with status 'Running'.
PowerShell
Invoke-Command -ComputerName Server03 -ScriptBlock { Get-Service | Where-Object { $_.Status [1] '[2]' } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-ne' (not equal) instead of '-eq'.
Using 'Stopped' instead of 'Running' as the filter value.
✗ Incorrect
To filter services with status 'Running', use the equality operator '-eq' and the string 'Running'.
5fill in blank
hardFill all three blanks to create a hashtable of service names and statuses from remote computers where status is not 'Stopped'.
PowerShell
$results = Invoke-Command -ComputerName Server04 -ScriptBlock { Get-Service | Where-Object { $_.Status [1] '[2]' } | ForEach-Object { @{ [3] = $_.Name; Status = $_.Status } } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-eq' instead of '-ne' for filtering.
Using 'ServiceName' instead of 'Name' as the hashtable key.
✗ Incorrect
To filter services not stopped, use '-ne' and 'Stopped'. The hashtable key for the service name is 'Name'.