0
0
PowerShellscripting~10 mins

Why cross-platform extends reach 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 print a message about cross-platform reach.

PowerShell
Write-Output [1]
Drag options to blanks, or click blank then click option'
Aecho Cross-platform scripts run on many systems.
B"Cross-platform scripts run on many systems."
CWrite-Output 'Cross-platform scripts run on many systems.'
DCross-platform scripts run on many systems.
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the string in quotes.
Using echo instead of Write-Output in PowerShell.
2fill in blank
medium

Complete the code to check the operating system platform.

PowerShell
$platform = [System.Environment]::OSVersion.Platform; if ($platform -eq [1]) { Write-Output "Windows detected" }
Drag options to blanks, or click blank then click option'
AWin32NT
B"Unix"
C"Darwin"
D"Linux"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong string for Windows platform.
Confusing platform strings with other OSes.
3fill in blank
hard

Fix the error in the script to detect Linux platform.

PowerShell
if ([System.Environment]::OSVersion.Platform -eq [1]) { Write-Output "Linux detected" }
Drag options to blanks, or click blank then click option'
A"OSX"
B"Win32NT"
CUnix
D"Darwin"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "Win32NT" or other strings which represent other platforms.
Not using the correct platform string for Linux.
4fill in blank
hard

Fill both blanks to create a cross-platform script that prints OS name.

PowerShell
$os = (Get-CimInstance -ClassName Win32_OperatingSystem -ErrorAction SilentlyContinue).[1]; if (-not $os) { $os = (uname).[2] }; Write-Output $os
Drag options to blanks, or click blank then click option'
ACaption
BToString
COutput
DName
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong property names for OS detection.
Not converting uname output to string.
5fill in blank
hard

Fill all three blanks to create a script that runs a command based on OS platform.

PowerShell
switch ([System.Environment]::OSVersion.Platform) { "Win32NT" { [1] 'dir' } "Unix" { [2] 'ls' } default { [3] 'Unsupported OS' } }
Drag options to blanks, or click blank then click option'
AWrite-Output
BInvoke-Expression
CWrite-Host
DStart-Process
Attempts:
3 left
💡 Hint
Common Mistakes
Using Write-Output instead of running commands.
Not handling default case properly.