2017-09-16 131 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