SubRoutine for WMIC that removes headers and blank spaces.

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Been thanked: 2 times
Contact:

SubRoutine for WMIC that removes headers and blank spaces.

Post by MigrationUser »

23 Jul 2009 22:05
Braven36


Does anyone have a subroutine that will remove the header and blank line of a wmic output? My subroutine in this script only work with certain queries. I would like one that will work with all wmic queries.

Code: Select all

if exist C:\scripts\citrix_install.txt del C:\scripts\citrix_install.txt


For /f %%a in (C:\scripts\computerlist.txt) do set node=%%a &call :citrix_install 

:Citrix_Install

For /f %%b in ('wmic /node:%node% service where name^="IMASERVICE" get name 2^>^&1') do call :[b]subRoutineCitrix[/b] %%b 

:[b]subRoutineCitrix [/b]
If /i {%1}=={} (
               goto :EOL

) else if /i {%1}=={NAME} (
               goto :EOL

) else If /i {%1}=={No} (
                  Set IMAservice=No 
                  goto :DOC

) else If /i {%1}=={IMASERVICE} (
                   set IMAservice=Yes
                   goto :DOC
)
:DOC
echo %node%,%IMASERVICE%,>>C:\scripts\citrix_install.txt
if defined %node% set node=
if defined %IMAservice% set IMAservice=


:EOL
----------------------------

#2 25 Jul 2009 16:49
bluesxman


The "FOR" command drops blank lines (whether you like it or not) and you can skip lines at the top with one of the command options. Something along these lines, perhaps?

Code: Select all

for /f "usebackq tokens=* skip=1" %%a in (`WMIC COMMAND HERE`) do echo:%%a
Last edited by bluesxman (25 Jul 2009 16:50)

cmd | *sh | ruby | chef

----------------------------

#3 27 Jul 2009 16:36
Braven36


This is output I am getting. The variable is not getting set. This make me believe there is a blank line being passed to the variable. Could you please test?

Thanks

Code: Select all

D:\>for /f "usebackq tokens=* skip=1" %a in (`WMIC service where name^="browser" get name`) do set Service=%a

 :\>set Service=Browser

D:\>echo %Browser%
%Browser%
----------------------------

#4 27 Jul 2009 17:56
bluesxman


You'll probably get a better result if you replace the last command with "echo %Service%"

Last edited by bluesxman (27 Jul 2009 17:57)

cmd | *sh | ruby | chef

----------------------------

#5 27 Jul 2009 18:35
Braven36


LOL... I missed that. It working now.

Anyways the skip part for command was what I was missing. I did not know that the output of the command between () was handle as if it were a text file once it was completed)

----------------------------

#6 27 Jul 2009 19:30
jumper

Code: Select all

WMIC service where(name="browser") get name | more +1
?

Last edited by jumper (27 Jul 2009 19:31)

----------------------------

#7 29 Jul 2009 23:14
Braven36


I have the issue with this code in a script

Code: Select all

For /f %%a in (C:\scripts\computerlist.txt) do set node=%%a &call :citrix_install 

:Citrix_Install
For /f "usebackq tokens=* skip=1" %%b in (`wmic /node:%node% service where name^="IMASERVICE" get name 2^>^&1`) do set IMASERVICE =%%b
This the results output

X:\>For /F "usebackq tokens=* skip=1" %b in (`wmic /node:server2 service where name="IMASERVICE" get name 2>&1`) do set IMASERVICE =%b

:\>set IMASERVICE =IMAService

:\>set IMASERVICE = <-for some reason it keep blanking out the variable here.

----------------------------

#8 30 Jul 2009 19:46
avery_larry


Get rid of the space before the equal sign and see what happens.

----------------------------

#9 31 Jul 2009 21:40
Braven36


It still has the same issues.

----------------------------

#10 01 Aug 2009 12:34
bluesxman


I think there's some strange CR at the end of the WMIC output. This should work (it works for me, at least):

Code: Select all

For /f "usebackq tokens=* skip=1" %%b in (`wmic /node:%node% service where name^="IMASERVICE" get name 2^>nul ^| findstr "." `) do set IMASERVICE=%%b
Last edited by bluesxman (01 Aug 2009 12:34)

cmd | *sh | ruby | chef
Post Reply