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