Re: WMI and Joining Domain (sysprep related)
- From: EricGus <eric.gustafson@xxxxxxxxxxxx>
- Date: Mon, 24 Mar 2008 14:10:38 -0700
Corey Thomas - MCSE/MCSA/MCDBA wrote:
> Hey Eric,
>
> If you have a database of info like the MAC, Serial, Computer name, domain,
> etc., you can use a vbscript to get info from the machine, then query the
> database, and rename the machine based on the results. You'll need to add
> this script to the bootini.cmd under c:\windows\temp after you sysprep.
> Just keep in mind that you have to rename the computer and reboot before you
> can join the domain.
> -Corey
Greg Wong wrote:
> Eric,
> I assume your machines go through a HW detection and reboot BEFORE they
> attempt to join your domain? If so, you could use this first "phase" to
> use a script to automaticaly generate a sysprep.inf file that includes
> the machine's name based on the MAC address. If you export your DB to
[...]
> write it to a sysprep.inf file. I do something similar to generate
> sysprep.infs for various sites in our Active Directory.
Thanks for the input which has, of course, shed a little more light on the entire process needing overhaul. I'll lay it all out (somewhat lengthy).
I just found out about cURL (http://curl.haxx.se/) and am now using a web address for my db queries from dos. I can probably alter the current output, which is wsname only, to include a OU name (if I were to use an OU field in the asset db) and subsequently do a full domain join including OU instead of the current track of simply renaming the pc.
Is it better to not have sysprep autojoin the domain but instead have a script join the domain. And can this run (ie: call wssetup.vbs) from the bootini.cmd?
I was unaware that there's a way to have something run between WDS imaging and the system rebooting and running sysprep. If they were vista boxes then I understand you can put that in WDS somehow but these are XP boxes...
Current process:
build box for master image
sysprep reseal mini-setup (with domain join)
upload to WDS
Workstation deployment:
1. Netboot and pull image from WDS
2. pc auto-reboots, runs minisetup & joins domain (sysprep.inf)
3. logon as local admin
4. rename pc (manually)
5. via another system, Move pc to proper OU
6. Reboot & SHOP group is added to local admins & Managed apps deployment per OU
7. Manually Run post install script & add local tcpip printers
Here's the script I've put together so far...
----8<----snip-----
option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''
''Get mac address & query for workstation name''
'''''''''''''''''''''''''''''''''''''''''''''''''
' dim objects for first section
Dim objWMISvc,objWMIService,ColItems,objItem,strComputername,objAdapter,colAdapters,n,AdapterDesc,MACAddress,MacAddressWithExtras
Dim wshShell,hwURL,cURLoptions,Return,objFSO,objFile,strContents,sps_hostname
Dim sps_barcode,Flag,ExtraMsg
strComputerName="."
'Check Os Version
if GetOS<>"WINXP" then
msgbox "Renaming PC Requires Windows XP or Vista" & vbCrLf & "Os installed is " & GetOS & _
vbCrLF & "Aborting Script..."
wscript.quit
end if
'Start WMI queries
ExtraMsg=""
Flag=False
Set objWMISvc = GetObject( "winmgmts:\\.\root\cimv2" )
Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
strComputerName = objItem.Name
Next
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerName & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
n = 1
For Each objAdapter In colAdapters
AdapterDesc=objAdapter.Description
MACAddress=objAdapter.MacAddress
' MACAddressWithExtras=MACAddress
MACAddress = Replace(MACAddress, ":", "") ' remove colons from MAC
n = n + 1
Next
' query hwaddr db
hwURL="http://myserver.edu/hwaddress/?hw_address="
cURLoptions="--output \workstation.nfo "
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
'Check for cURL
If objFSO.FileExists("c:\windows\curl.exe") Then
Flag=True
end if
if Flag=False then
wscript.echo "cURL not found in C:\windows\" & vbCrLf & " Aborting..."
wscript.Quit
end if
Return = WshShell.Run("c:\windows\curl.exe " & cURLoptions & hwURL & MACAddress, 0, true)
if Return<>0 Then
wscript.echo "Return Code=" & Return
end if
' read hwaddr textfile that was created from query then delete it
Const ForReading = 1
If objFSO.FileExists("\workstation.nfo") Then
Set objFile = objFSO.OpenTextFile("\workstation.nfo", ForReading)
strContents = objFile.ReadAll
sps_hostname=strContents
objFile.Close
End If
If objFSO.FileExists("\workstation.nfo") Then
objFSO.DeleteFile "\workstation.nfo"
End If
if len(sps_hostname)>7 then
sps_barcode=mid(sps_hostname,4,5) 'pick the 5 chars starting at 4th position for use as the barcode
end if
'''''''''''''''''''''''''''''''''''''''''''''''''
'' Get workstation BIOS info for oeminfo ''
'''''''''''''''''''''''''''''''''''''''''''''''''
' Dim objects for BIOS section
Dim BIOS,strSN,Model,strModel,Manufacturer,strManufacturer,Instance
Set BIOS = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strComputerName & "/root/cimv2").ExecQuery("select Caption,SerialNumber,Name from Win32_BIOS")
For Each Instance In BIOS
If Instance.Caption = "" then Exit For
strSN = Instance.SerialNumber
Set BIOS = Nothing
Next
Set Model = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strComputerName & "/root/cimv2").ExecQuery("select Model from Win32_ComputerSystem")
For Each Instance In Model
If Instance.Model = "" Then Exit For
strModel = Instance.Model
set BIOS = Nothing
Next
Set Manufacturer = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strComputerName & "/root/cimv2").ExecQuery ("select Manufacturer from Win32_ComputerSystem")
For Each Instance In Manufacturer
If Instance.Manufacturer = "" Then Exit For
strManufacturer = Instance.Manufacturer
if (len(strManufacturer)>=4 and left(strManufacturer,4)="Dell") then
strManufacturer="Dell"
end if
Set Manufacturer = Nothing
Next
' Check to see if workstation name is already named properly
' If so, then quit
if strComputerName=sps_hostname then
ExtraMsg="Pc Is Already Named Properly....Aborting Script" & _
vbcrlf & "==============================================" & vbCrLf & vbCrLf
call DisplayInfo
Wscript.Quit
End if
'''''''''''''''''''''''''''''''''''''''''''''''''
'' Write OEMINFO & Logo ''
'''''''''''''''''''''''''''''''''''''''''''''''''
dim fname,path,getname
fname="c:\windows\system32\oeminfo.ini"
Set objFile = objFSO.CreateTextFile(fname, True) ' True=Overwrite OK
objFile.WriteLine("[General]")
objFile.WriteLine ("Manufacturer= " & strManufacturer)
objFile.WriteLine ("Model= " & strModel)
objFile.WriteLine ("SupportURL=http://helpdesk")
objFile.WriteLine ("[Support Information]")
objFile.WriteLine ("Line1=Property Of Springfield Public Schools")
objFile.WriteLine ("Line2= --------------------------")
objFile.WriteLine ("Line3=For Technical Support")
objFile.WriteLine ("Line4=Contact the Support Desk")
objFile.WriteLine ("Line5=WEB http://helpdesk")
objFile.WriteLine ("Line6=")
objFile.WriteLine ("Line7=When contacting Computer Services for support,please")
objFile.WriteLine ("Line8=have the following information available:")
objFile.WriteLine ("Line9=")
objFile.WriteLine ("Line10=Asset Tag: " & strSN)
objFile.WriteLine ("Line11=Barcode: " & sps_barcode)
objFile.WriteLine ("Line12=Machine ID: " & sps_hostname)
objFile.Close
objFSO.CopyFile "\\file1\gpo_managed\PostInstall\oemlogo.bmp", "c:\windows\system32\", True
'''''''''''''''''''''''''''''''''''''''''''''''''
'' Rename PC ''
'''''''''''''''''''''''''''''''''''''''''''''''''
Dim User,Password,objComputer,Result
User="myadminuser"
Password="myadminpassword"
Set objWMIService = GetObject("Winmgmts:root\cimv2")
' Call always gets only one Win32_ComputerSystem object.
For Each objComputer in _
objWMIService.InstancesOf("Win32_ComputerSystem")
Result = objComputer.rename(sps_hostname,Password,User)
If Result <> 0 Then
WScript.Echo "Rename failed. Error = " & Err.Number
Else
ExtraMsg="Workstation Renamed from: " & strComputername & _
VbCrLf & "to " & sps_hostname & VbCrLf & _
"System Must be rebooted to take effect" & vbCrLf & _
"==============================================" & vbCrLf
Call DisplayInfo
End If
Next
'Reboot
Result=msgbox ("Click ok to Restart or X to exit",49)
If Result=1 Then
call Restart
else if Result=2 Then
wscript.echo "reboot Cancelled"
end if
End If
Wscript.Quit
' Display PC Info (for debug)
Sub DisplayInfo
wscript.echo (ExtraMsg & "********************************" & vbCrLf & _
"* Workstation Renaming Info *" & vbCrLf & "********************************" & vbCrLf & _
"SPS Barcode:" & sps_barcode & vbCrLf & _
"Helpdesk WS Name: " & sps_hostname & vbCrLf & _
"Current WS Name : " & strComputerName & vbCrLf & "Network Adapter: " & n & vbCrLf & _
"Description : " & AdapterDesc & vbCrLf & "MAC address : " & _
MACAddress & vbCrLf & vbCrLf & "*************" & vbCrLf & _
"* BIOS Info *" & vbCrLf & "*************" & vbCrLf & _
"Manufacturer: " & strManufacturer & vbCrLf & "Model: " & strModel & vbCrLf & _
"Serial: " & strSN & vbCrLf)
End Sub
' REBOOT PC
Sub Restart
wshShell.Run "%WINDIR%\System32\shutdown.exe /r /t 0 /f /d p:2:4", 0
End Sub
' Determine Os Version..
Function GetOS()
Dim strWMIOS,objOS,strOsVer
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerName & "\root\cimv2")
Dim strOsQuery : strOsQuery = "Select * from Win32_OperatingSystem"
Dim colOperatingSystems : Set colOperatingSystems = objWMIService.ExecQuery(strOsQuery)
For Each objOs in colOperatingSystems
strWmios = objOs.Caption & " " & objOs.Version
Next
Select Case True
'For Vista, this sets GetOS to XP so script will run.
Case InStr(strWmiOS, "2000 Server") > 1 : GetOS = "2KSRV"
Case InStr(strWmiOS, "2003, Standard") > 1 : GetOS = "2K3SRV"
Case InStr(strWmiOS, "2003, Enterprise") > 1 : GetOS = "2K3ENTSRV"
Case InStr(strWmiOS, "2000 Advanced Server") > 1 : GetOS = "2KADVSRV"
Case InStr(strWmiOS, "Windows NT") > 1 : GetOS = "NT4"
Case InStr(strWmiOS, "Windows 2000") > 1 : GetOS = "WIN2K"
Case InStr(strWmiOS, "Windows XP") > 1 : GetOS = "WINXP"
Case Instr(strWmiOS, "Vista") > 1 : GetOS = "WINXP"
Case Else : GetOS = "UnKnown"
End Select
End Function
----8<----snip-----
.
- References:
- WMI and Joining Domain (sysprep related)
- From: EricGus
- WMI and Joining Domain (sysprep related)
- Prev by Date: Re: Need script to find I/O Reads of a specified process
- Next by Date: Re: stdout.writeline output issue
- Previous by thread: Re: WMI and Joining Domain (sysprep related)
- Next by thread: How to read text files on remote servers without mapping/unmapping drives?
- Index(es):
Relevant Pages
|