Reading WMI (Serialnumber) before windeploy.exe RRS feed

  • Question

  • 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?


    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 5, 2014 3:19 AM
    • Moved by Bill_Stewart Monday, June 30, 2014 5:15 PM Off-topic
    Wednesday, February 5, 2014 1:35 AM

All replies

  • Fails? What does "fails" mean.  How do you know it fails? What is you script? What is the error?


    Wednesday, February 5, 2014 2:00 AM
  • 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}


    Wednesday, February 5, 2014 3:21 AM
  • 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.


    Wednesday, February 5, 2014 4:01 AM
  • 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.

    Wednesday, February 5, 2014 4:28 AM
  • 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



    • Edited by jrv Wednesday, February 5, 2014 4:42 AM
    Wednesday, February 5, 2014 4:41 AM
  • Hah! Pasted the wrong thing and now I can't delete it.


    Wednesday, February 5, 2014 4:43 AM
  • Hah! Pasted the wrong thing and now I can't delete it.


    I love it, needed to see that !

    The "gwmi Win32_bios" works fine after the Sysprep/First boot is complete, and it works in Audit mode, before I seal the image with sysprep.

    Wednesday, February 5, 2014 4:50 AM
  • It is pretty clear now that this is not a scripting issue.  You might try posting in the deployment forum.


    Wednesday, February 5, 2014 1:14 PM
  • 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


    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 5, 2014 10:28 PM
    Wednesday, February 5, 2014 10:01 PM
  • 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.

    Wednesday, February 5, 2014 10:23 PM