繁体   English   中英

如何在批处理文件中运行此 powershell 脚本

[英]How can I run this powershell script in a batch file

如何在批处理文件中运行此 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.....但我不知道如何写这样的句子

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM