Bird
0
0

How can you combine PowerShell on Linux with native Linux commands to count the number of active SSH connections?

hard📝 Application Q9 of 15
PowerShell - Cross-Platform PowerShell
How can you combine PowerShell on Linux with native Linux commands to count the number of active SSH connections?
A$count = (bash -c "ss | grep ssh | wc -l") -as [int]
B$count = Get-Process ssh | Measure-Object | Select-Object -ExpandProperty Count
C$count = (Get-NetTCPConnection -State Established | Where-Object { $_.RemoteAddress -like '*ssh*' }).Count
D$count = (Invoke-Command -ScriptBlock { ss | grep ssh | wc -l })
Step-by-Step Solution
Solution:
  1. Step 1: Use bash -c to run native Linux commands

    Running 'ss | grep ssh | wc -l' inside bash counts SSH connections; bash -c executes this from PowerShell.
  2. Step 2: Cast output to integer

    Output is string; casting with -as [int] converts it to integer for counting.
  3. Final Answer:

    $count = (bash -c "ss | grep ssh | wc -l") -as [int] -> Option A
  4. Quick Check:

    Use bash -c and cast output to int [OK]
Quick Trick: Use bash -c to run Linux commands and cast output to int [OK]
Common Mistakes:
  • Using Get-Process for network connections
  • Using Get-NetTCPConnection which is Windows-only
  • Misusing Invoke-Command for local Linux commands

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes