這個問題在這里已經有了答案: 如何更改 PowerShell 變數代碼以便我可以通過 CMD 運行它? (4 個回答) 3天前關閉。
如何在批處理檔案中運行此 PowerShell 腳本?
(netsh wlan show profiles) | Select-String "\:(. )$" |
%{$name=$_.Matches.Groups[1].Value.Trim(); $_} |
%{(netsh wlan show profile name="$name" key=clear)} |
Select-String "Key Content\W \:(. )$" |
%{$pass=$_.Matches.Groups[1].Value.Trim(); $_} |
%{[PSCustomObject]@{ PROFILE_NAME=$name;PASSWORD=$pass }} |
Format-Table -AutoSize >> "Wifi.txt"
我找到了一些解決方案,但是我找不到常規的方法,所以我無法解決這個問題。
我想在批處理檔案中的一行中運行所有 PowerShell 行,例如powershell.exe -command.....,但我不知道如何將這樣的句子放入。
uj5u.com熱心網友回復:
PowerShell 合二為一
netsh wlan show profiles|SLS "\:(. )$"|%{$SSID=$_.Matches.Groups[1].Value.Trim(); $_}|%{(netsh wlan show profile name="$SSID" key=clear)}|SLS "Conte.*:(. )$"|%{$pass=$_.Matches.Groups[1].Value.Trim(); $_}|%{[PSCustomObject]@{SSID=$SSID;PASSWORD=$pass}}
使用混合批處理檔案/PowerShell:
<# : batch script
@rem # The previous line does nothing in Batch, but begins a multiline comment block in PowerShell. This allows a single script to be executed by both interpreters.
@echo off
Title Wifi Passwords Recovery
setlocal
cd "%~dp0"
Color 0B & echo(
Echo( Please Wait a while ... Executing the PowerShell command ...
powershell -executionpolicy remotesigned -Command "Invoke-Expression $([System.IO.File]::ReadAllText('%~f0'))"
If Exist WifiKeys.txt Start /MAX "" WifiKeys.txt
EndLocal
goto:eof
#>
# Here write your PowerShell commands...
netsh wlan show profiles|SLS "\:(. )$"|%{$SSID=$_.Matches.Groups[1].Value.Trim(); $_}|%{(netsh wlan show profile name="$SSID" key=clear)}|SLS "Conte.*:(. )$"|%{$pass=$_.Matches.Groups[1].Value.Trim(); $_}|%{[PSCustomObject]@{SSID=$SSID;PASSWORD=$pass}}>WifiKeys.txt
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/507894.html
