I've looked at all these threads and posts:
Thread: https://superuser.com/questions/1082530/how-can-i-remove-the-last-blank-line-of-a-wmic-command
Thread: How can I remove empty lines from wmic output?
Thread: Parsing WMIC output
Post: https://stackoverflow.com/a/37725658/8262102
So far and none help and most of them use findstr /r /v "^$"
to do this.
The issue with them all is that in my case the output contains an additional line when written to a file.
My desired output to file should be:
[Microsoft Windows 10 Pro]
but I'm getting:
[Microsoft Windows 10 Pro
]
Here's my code which will create the output file on your desktop:
@echo off
Setlocal EnableDelayedExpansion
cd /d "C:\Users\%username%\Desktop"
(
for /f "skip=1 delims=" %%A in (
'wmic OS get Caption ^| findstr /r /v "^$"'
) do echo [%%A]
)>output.txt && exit
Any help would be greatly appreciated.