1

I am trying to get all known WiFi SSIDs including the Password.

When I use the following command called from a batch file, I can't get it to work. I get the following error:

Can someone please help me?

powershell -command "(netsh wlan show profiles) | Select-String "\:(.+)$" | %{$name=$_.Matches.Groups[1].Value.Trim(); $_} | %{(netsh wlan show profile name="$name" key=clear)} >> %computername%.txt"

In Zeile:1 Zeichen:54
+ ... ng \:(.+)$ | {(netsh wlan show profile name=$name key=clear)} >> MEHL ...
+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ausdrücke sind nur als erstes Element einer Pipeline zulässig.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline
Markus
  • 41
  • 1
  • 4
  • 2
    The `%` characters need escaping in a batch file. Change both of them to `%%`. Then your nested doublequotes require escaping. Change `"\:(.+)$"` to`\"\:(.+)$\"` and `"$name"` to `\"$name\"`. – Compo Jul 22 '23 at 10:03
  • I would do it in this _simpler_ way: `powershell (netsh wlan show profiles) ^| Select-String \"\:(.+)$\" ^| %%{$name=$_.Matches.Groups[1].Value.Trim(); $_} ^| %%{(netsh wlan show profile name="$name" key=clear)} >> %computername%.txt` – Aacini Jul 22 '23 at 15:37
  • *PowerShell* is the successor of the *Windows Command Processor* `cmd.exe` processing a batch file. There is no need to call *PowerShell* by `cmd.exe`. The single __batch__ command line `for /F "tokens=1* delims=:" %%G in ('%SystemRoot%\System32\netsh.exe wlan show profile 2^>nul ^| %SystemRoot%\System32\find.exe ":"') do for /F "tokens=*" %%I in ("%%H") do for /F "tokens=3*" %%J in ('%SystemRoot%\System32\netsh.exe wlan show profile name^="%%I" key^=clear ^| %SystemRoot%\System32\find.exe "Key Content"') do echo ssid: %%I pass: %%K` outputs the data of interest on execution as administrator. – Mofi Jul 22 '23 at 17:37

1 Answers1

0

You can use this method with hybrid code Batch and PowerShell in order to get what you want as result :

<# : Batch Script Section
@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 by Hackoo 2023 & Mode 70,3
setlocal
cd "%~dp0"
Color 0B & echo(
Echo(      Please Wait a while ... Getting SSID and Wifi Keys ...
Powershell -executionpolicy bypass -Command "Invoke-Expression $([System.IO.File]::ReadAllText('%~f0'))"
EndLocal
goto:eof
#>
# Powershell Script Section begin here...
# here we execute our powershell commands...
$Var=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}}
$var | Format-List | Out-File -FilePath ".\WifiKeys_List_Format.txt"
$var | ConvertTo-Json | Out-File -FilePath ".\WifiKeys_JSON_Format.txt"
$var | OGV -Title "Wifi Passwords Recovery by Hackoo 2023" -wait
ii ".\WifiKeys_JSON_Format.txt"
ii ".\WifiKeys_List_Format.txt"
Hackoo
  • 18,337
  • 3
  • 40
  • 70