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?


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 1:35am

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 05, 2014 10:28 PM
Free Windows Admin Tool Kit Click here and download it now
February 5th, 2014 10:01pm

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

Other recent topics Other recent topics