PowerShell - Cross-Platform PowerShellHow 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 CountC$count = (Get-NetTCPConnection -State Established | Where-Object { $_.RemoteAddress -like '*ssh*' }).CountD$count = (Invoke-Command -ScriptBlock { ss | grep ssh | wc -l })Check Answer
Step-by-Step SolutionSolution:Step 1: Use bash -c to run native Linux commandsRunning 'ss | grep ssh | wc -l' inside bash counts SSH connections; bash -c executes this from PowerShell.Step 2: Cast output to integerOutput is string; casting with -as [int] converts it to integer for counting.Final Answer:$count = (bash -c "ss | grep ssh | wc -l") -as [int] -> Option AQuick 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 connectionsUsing Get-NetTCPConnection which is Windows-onlyMisusing Invoke-Command for local Linux commands
Master "Cross-Platform PowerShell" in PowerShell9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PowerShell Quizzes Active Directory - AD module installation - Quiz 7medium Active Directory - Bulk user operations from CSV - Quiz 7medium Active Directory - Group management - Quiz 14medium Automation Patterns - Configuration drift detection - Quiz 10hard Cross-Platform PowerShell - REST API calls with Invoke-RestMethod - Quiz 4medium Remote Management - SSH-based remoting (PowerShell 7+) - Quiz 9hard Scripting Best Practices - Code signing - Quiz 11easy System Administration - Windows features management - Quiz 15hard System Administration - Environment variables - Quiz 4medium System Administration - Scheduled task management - Quiz 7medium