Reading WMI (Serialnumber) before windeploy.exe

I have written a Powershell script to read the Serialnumber of a device, and then use this to name the device. 

The line of code is :

$strSerial = gwmi Win32_BIOS | ForEach {$_.SerialNumber}

The script then looks up the serial in a file, finds a matching computer name, and rewrites the unattend.xml file with the new name.  This is set in the registry to run before Windeploy.exe in the registry.  Once complete, the script starts Windeploy.exe.

When I test the script in a normal Windows 8 session, it works fine, finding the serial, looking up the correct name, and editing the unattend.xml file.  However, when I fully run it before the Windeploy.exe, it fails when trying to access WMI, at the line above.

(This is a simple, standalone machine, no Group Policies, AD, etc.)

Is there a reason I am unable to get this code to work?

Thanks.

Edit: Here is the error in the "Administrator: Windows Powershell" Box

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

gwmi : Critical error

At C:\Windows\Setup\Scripts\PreDeploy.ps1:87 char:14

+$strSerial = gwmi Win32_BIOS | ForEach {$_.SerialNumber}

+                   ~~~~~~~~~~~~

+CategoryInfo :InvalidOperation: (:) [Get-WmiObject], ManagementExecption+FullyQualifiedErrorId : GetWMIManagementException, Microsoft.Powershell.Commands.GetWmiObjectCommand

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


  • Edited by Mickers_au Wednesday, February 05, 2014 3:19 AM
  • Moved by Bill_Stewart Monday, June 30, 2014 5:15 PM Off-topic
February 5th, 2014 4:35am

Fails? What does "fails" mean.  How do you know it fails? What is you script? What is the error?
Free Windows Admin Tool Kit Click here and download it now
February 5th, 2014 5:00am

I've added the exact error code to my original post, the actual line of code that errors was this one, in my original post.

$strSerial = gwmi Win32_BIOS | ForEach {$_.SerialNumber}

Thanks.

February 5th, 2014 6:21am

If that is giving you an error then you have a corrupted system.

Are you running as an admin?

What OS are you running?

If you are running WinPE then you may not have all of WMI loaded.

Free Windows Admin Tool Kit Click here and download it now
February 5th, 2014 7:01am

OK, thanks.

I've built a clean Win8_64 VM (VMWare Workstation 9), straight to Audit mode, patched it up to current using WindowsUpdate, then started to test my sysprep scripts.

I'm in as Administrator (Audit-mode, no other accounts created yet), and not using WinPE.  Rebuilding the Win8 VM is probably the one thing I hadn't tried.  Will test that, thanks.

February 5th, 2014 7:28am

Well you didn't post the whole error but from the part I can see it certainly looks like a corrupt system.

I see no reason why a class as fundamental should not work.YOu might try typinh this at a prompt to be sure it works:

gwmi Win32_BIOS

s

Free Windows Admin Tool Kit Click here and download it now
February 5th, 2014 7:41am

Hah! Pasted the wrong thing and now I can't delete it.

February 5th, 2014 7:43am

Hah! Pasted the wrong thing and now I can't delete it.

Free Windows Admin Tool Kit Click here and download it now
February 5th, 2014 7:50am

It is pretty clear now that this is not a scripting issue.  You might try posting in the deployment forum.
February 5th, 2014 4:14pm

I will repost in that forum, thanks.

Just FYI,

-I rebuilt the Win8 VM from scratch

-Straight into Audit mode

-Copied over the scripts/unattend files

-sysprepped (with /quit)

-changed reg entry to start PreDeploy.ps1 rather than windeploy.exe

-Reboot

Exactly the same error.

Also, on a hunch, I tried running a Windows Batch file which reads the same WMI info ('wmic bios get serialnumber') instead of the Powershell script, and it worked fine.


  • Edited by Mickers_au Wednesday, February 05, 2014 10:28 PM
Free Windows Admin Tool Kit Click here and download it now
February 6th, 2014 1:01am

Sorry to be a noob, but in 20 years as an IT professional, this is the first time I've ever had to post in a MS forum :-)

Can you point me to the 'deployment forum'? I have searched and can't seem to find one.

February 6th, 2014 1:23am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics