0

I'm trying to detect the SSID that my Windows 10 laptop is connected to, and deciding what to do based on the detected SSID. I'm able to detect the SSID via the following command:

netsh wlan show interfaces | findstr /r "^....SSID"

This command output is as such:

    SSID                   :my_ssid    

I'm trying to assign this string output to a variable with the following command:

set ssid=
for /f %%i in ('netsh wlan show interfaces | findstr /r "^....SSID"') do set ssid=%%i
echo SSID is "%ssid%"

However, I keep getting the following error message:

| was unexpected at this time.

Does anyone know why?

Also, is it possible to strip the netsh output of the "SSID", ":" and the whitespace so that I get only "my_ssid" as the output?

1 Answer 1

1

When you use a pipe in a for loop, you need to escape it with a ^. Otherwise, the interpreter thinks you're piping the entire loop up to that point and for /f %%i in ('netsh wlan show interfaces isn't valid syntax.

for /f %%i in ('netsh wlan show interfaces ^| findstr /r "^....SSID"') do set ssid=%%i
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.