Need some help in Batch file assigning variable value ?

Posted on 2016-10-17
Last Modified: 2016-10-17

Can anyone here please assist me with the batch script below:

C:\WINDOWS\system32>bcdedit /store C:\WinPE_Combined\Media\Boot\BCD /enum | find "osdevice"
osdevice                ramdisk=[boot]\sources\boot.wim,{7619daa8-fafa-11d9-b411-000476eba66e}

Open in new window

I need to assign like this OSID={7619daa8-fafa-11d9-b411-000476eba66e}

Thanks in advance.
  • 2
  • 2
LVL 23

Accepted Solution

NVIT earned 500 total points
ID: 41847518
for /f "tokens=2 delims=," %%a in ('bcdedit /store C:\WinPE_Combined\Media\Boot\BCD /enum ^| find "osdevice"') do (
  set OSID=%%a
  echo OSID=%OSID%

Open in new window


Author Comment

by:Senior IT System Engineer
ID: 41847537
THanks NVIT,

but somehow:

%%a was unexpected at this time.

Open in new window

LVL 23

Assisted Solution

NVIT earned 500 total points
ID: 41847547
Because it's supposed to be saved in a bat file.
If you run it on the the CMD line, change all the %% to %

Author Closing Comment

by:Senior IT System Engineer
ID: 41847622
Thanks man !
yes it works.

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now