2017-09-16 85 views
0

我对脚本不太熟悉,目前我正在尝试一个脚本来检查你连接的ssid。
如果它是安全的,它会显示你是安全的,如果你连接到一个开放的WiFi它会告诉你,你是不安全的。Powershell如果声明不起作用

文件下面

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 

因为即时通讯的任何援助欣赏完全没了主意,现在

感谢

+2

你在这里有什么错误?什么不工作? – vrdse

+0

WhenAuthentication打开它仍然是标记是安全的,虽然它应该标记为不安全 –

回答

3

你检查$wifi.Profile -eq 'Open'$wifi.Profile是配置文件的名称,通常是SSID你连接到。可能你必须比较$wifi.Authentication。但是,您可以通过输出$wifi对象轻松验证正确的属性。

+0

更改$ wifi.profile -eq'打开'为$ wifi.authentication -eq'打开' –

+0

感谢您的帮助 –

+0

@kurtattard如果你发现一个有用的答案,你应该考虑[接受答案](http://stackoverflow.com/help/accepted-answer)和/或[投票](https://stackoverflow.com/help/为什么票) – LotPings