Hi,
By running the following query, I get my response with headers (IPAddressName and InstanceName) which I want to eliminate
wmic /NameSpace:\\root\Microsoft\SqlServer\ComputerManagement11 Path ServerNetworkProtocolProperty where (PropertyName='IPAddress' or IPAddresName='IPAll') get IPAddressName, InstanceName
so I am running the following
for /f "skip=1 tokens=1,2 delims= " %a in ('wmic /NameSpace:\\root\Microsoft\SqlServer\ComputerManagement11 Path ServerNetworkProtocolProperty where ^(PropertyName^='IPAddress' or IPAddressName^='IPAll') get InstanceName^, IPAddressName'^) do @echo %a %b
but I am getting error (get was unexpected at this time)
What I am doing wrong?
WMIC query in for loop
Moderator: DosItHelp
Re: WMIC query in for loop
Test the cmd prompt version of the command and verify that it returns the data you need.
Then paste it here and you may get a workaround.
In essence you can double quote the entire command and avoid escaping terms, like this:
Then paste it here and you may get a workaround.
In essence you can double quote the entire command and avoid escaping terms, like this:
Code: Select all
@echo off
setlocal enabledelayedexpansion
(For /F "tokens=1,* delims==" %%A in ('"wmic OS get FreePhysicalMemory,TotalVisibleMemorySize /value |find "M" "') do (
set "line=%%A= %%B"
set "line=!line:~0,-1!"
echo !line!
))
pause
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: WMIC query in for loop
Is that going to work with find also using double quotes?
Re: WMIC query in for loop
ShadowThief wrote:Is that going to work with find also using double quotes?
Sure does.
Re: WMIC query in for loop
foxidrive wrote:ShadowThief wrote:Is that going to work with find also using double quotes?
Sure does.
Actually, that depends on what is inside the inner set of quotes, because they will no longer be quoted during the parent script parsing. Any poison characters would need to be escaped.
Dave Benham
Re: WMIC query in for loop
Double quotes did the trick. Thanks!
I am getting desired output except that the last line I get "Echo is on". I copied the command in .cmd file with @echo off in the beginning but it still does it.
I am getting desired output except that the last line I get "Echo is on". I copied the command in .cmd file with @echo off in the beginning but it still does it.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: WMIC query in for loop
That's the message you get when you try to print an empty variable. It sounds like !line! isn't equal to anything at some point.
Re: WMIC query in for loop
yeah, WMIC outputs things like two carriage returns at the same time without line feeds, etc.
There are workarounds - the one that is used depends on the command line and the data being extracted.
You can redirect the WMIC output into a text file and use a Hex viewer/editor to see the actual output and where the problem is.
There are workarounds - the one that is used depends on the command line and the data being extracted.
You can redirect the WMIC output into a text file and use a Hex viewer/editor to see the actual output and where the problem is.