简体   繁体   中英

Powershell if Statement not working

I am not so much familiar with scripting, currently Im trying a script to check the ssid that you are connected to.
If it is secured it will display you are secure and if you are connected to an open wifi it will tell you that you are not secure.

Script below

function Test-WiFiSecured{
    $props = netsh wlan show interfaces | 
        Select-Object -skip 4 |
        Where{$_.Trim()} |
        ForEach-Object{ $_ -replace ':', '=' } |
        Out-String |
        ConvertFrom-StringData
    $wifi = [pscustomobject]$props
    Write-Host 'Authentication='$wifi.Authentication -ForeGround Green
    if($wifi.Profile -eq 'Open'){
        Write-Host 'Not secure' -ForeGround Red
    } else {
        Write-Host 'Secure connection' -ForeGround Green
        return $true
    }
}
Test-WiFiSecured  

Any assistance is appreciate since Im totally out of ideas now

Thanks

You are checking for $wifi.Profile -eq 'Open' but $wifi.Profile is the profile name, usually the SSID you are connected to. Probably you have to compare $wifi.Authentication . However, you can easily verify the correct property by output the $wifi object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM