kurt attard
kurt attard

Reputation: 5

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

Upvotes: 0

Views: 91

Answers (1)

vrdse
vrdse

Reputation: 3154

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.

Upvotes: 3

Related Questions