Link to home
Start Free TrialLog in
Avatar of Garry Shape
Garry ShapeFlag for United States of America

asked on

Command prompt output to variable?

I am trying to get a package name (which varies on each computer, but all have in common the string "embeddedlock") in order to pass to DISM /Remove-Package command.

If I run:

for /f "delims=" %a in ('dism /online /get-packages ^| findstr /I "embeddedlock"') do @set myvar=%a   

Open in new window

Then I get the following output:

Package Identity : Microsoft-Windows-Embedded-EmbeddedLockdown-Package-TopLevel~31bf3856ad364e35~amd64~~7.1.7601.17116

Is there A) a better way to get this output, and B), a way to get rid of the "Package Identity : " part, so that I can pass the variable to the command:  

DISM /online /Remove-Package /PackageName:Microsoft-Windows-Embedded-EmbeddedLockdown-Package-TopLevel~31bf3856ad364e35~amd64~~7.1.7601.17116 /quiet /norestart

Open in new window

Avatar of NVIT
NVIT
Flag of United States of America image

Add this below your first FOR.
for /f "tokens=2* delims=:" %a in ('echo %myvar%') do @set myvar2=%a

Open in new window

DISM /online /Remove-Package /PackageName:%myvar2%

Open in new window

Avatar of Garry Shape

ASKER

sweet that works. only there is a space before the first word. " Microsoft"
since there's a space after the colon character.
do I need to add space in delims=?
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Amazing! Thanks so much!
You're welcome. Have a nice day...
Sorry one other question on this.
Incorporating this into a batch .cmd file, do I need to add extra percentage symbols/%?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok thanks. Here's what I made it to work with PDQ Deploy:

for /f "delims=" %%a in ('dism /online /get-packages ^| findstr /I "embeddedlock"') do @set myvar=%%a
for /f "tokens=2* delims=:" %%a in ('echo %myvar%') do @set myvar2=%%a
setlocal DisableDelayedExpansion
set myvar2=%myvar2:~1%
DISM /online /Remove-Package /PackageName:%myvar2%

Open in new window

PDQ Deploy is a great program.