I am creating a script to monitor if a pc has more than one network connection, ie wired and wireless. The script below does not seem to work with the count option for the array. It just returns 0.

param(
    [string]$ComputerName = "",
    [array]$myNetCon = @()
)

$myNetCon += Get-Netadapter -cimsession $ComputerName -physical | where status -eq 'up'

if($myNetCon.Count -gt 1)
    {
    Write-Host("0:BAD")
    }
    else
    {
    Write-Host ("1:OK")
    }

Article Comments

Your script seems sound.

Are you running it with the "Security Context" set to "Use Windows credentials of parent device" and an account with permission on the target device(s)?


Dec, 2019 - Permalink

Yes, i have those set. I have since learnt that i needed the Invoke command as my script only ran on the core server. I have done this but still no joy.


Dec, 2019 - Permalink

Looking at the logs is say it failed to connect to the destination specified in the request. OpenError PSRemotingTransportException.

I have checked winrm and all looks fine and i can use the remote powershell from the core server to run remote commands on the PC.


Dec, 2019 - Permalink

Hi there,

Please make sure that the execution policy for the x32 Powershell is configured correctly. You can find more information about this and other troubleshooting steps in this article.


Kind regards,
Birk Guttmann, Tech Support Team


Dec, 2019 - Permalink