2017-03-04 70 views
0

我想創建WLAN配置文件白名單,我要刪除...Exec的動態PowerShell腳本

$whitelist = "mywifi1", "mywifi2", "mywifi3"

然後遍歷我所有的使用WLAN配置文件...

netsh wlan show profiles

並執行所有這些以下除的那些在我WHI telist ...

'的netsh wlan的刪除配置文件名稱= 「@」

其中@是配置文件的名稱。

回答

0

嗯,我不認爲有一種方法可以做到這一點沒有一些字符串操作,這對我來說是這樣的:

$whitelist = "mywifi1", "mywifi2", "mywifi3" 
$netshoutput = netsh wlan show profiles | select -Skip 9 
$profiles = $netshoutput.ForEach({$_.split(' ')[-1]}) 
$profiles.ForEach({ if ($_ -notin $whitelist) {netsh wlan delete profile name="$_"}}) 

我不知道,你還需要精確地切前9行,你必須測試它。編輯:忘了添加白名單標準

+0

謝謝。我會給你一個鏡頭並回報。 –