Garry Shape
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:
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:
If I run:
for /f "delims=" %a in ('dism /online /get-packages ^| findstr /I "embeddedlock"') do @set myvar=%a
Then I get the following output: Package Identity : Microsoft-Windows-Embedded-EmbeddedL ockdown-Pa ckage-TopL evel~31bf3 856ad364e3 5~amd64~~7 .1.7601.17 116
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
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=?
since there's a space after the colon character.
do I need to add space in delims=?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Amazing! Thanks so much!
You're welcome. Have a nice day...
ASKER
Sorry one other question on this.
Incorporating this into a batch .cmd file, do I need to add extra percentage symbols/%?
Incorporating this into a batch .cmd file, do I need to add extra percentage symbols/%?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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%
PDQ Deploy is a great program.
Open in new window
Open in new window