Een collega kwam met een opzetje wat na wat finetuning hierop uitkwam (IP addressen uiteraard weggelaten):
___________
Const ForReading = 1
Const ForWriting = 2
' ask user for region and validate
numRegion=inputbox("Please choose region: 1.ASIA, 2.EUROPE, 3.WHEM")
if isnumeric(numRegion) =false then
msgbox("Invalid region number entered, quitting.")
wscript.quit
end if
if numRegion <1 or numregion >3 then
msgbox("Invalid region number entered, quitting.")
wscript.quit
end if
' define regional path
Select Case numRegion
Case 1
strPath = "\\xxx\esx$\"
strKS = strPath & "ASIA\KS.cfg"
strWebsite = "http://xxx/esx/"
Case 2
strPath = "\\xxx\esx$\"
strKS = strPath & "EUR\KS.cfg"
strWebsite = "http://xxx/esx/"
Case 3
strPath = "\\xxx\esx$\"
strKS = strPath & "WHEM\KS.cfg"
strWebsite = "http://xxx/esx/"
End Select
' define variables to replace in template script file
strToReplacehostname = "%HOSTNAME%"
strToReplaceip = "%IPADDRESS%"
strToReplacemask = "%NETMASK%"
strToReplacegw = "%DEFGW%"
strToReplacedns1 = "%DNSSERVER1%"
strToReplacedns2 = "%DNSSERVER2%"
strToReplacetimezone = "%TIMEZONE%"
' request server data
strhostname=inputbox("Enter Server Hostname")
strip=inputbox("Enter Server Service Console IP address")
strmask=inputbox("Enter Server Net mask")
strgw=inputbox("Enter Server Default gateway")
strdns1=inputbox("Enter Primary DNS server IP address")
strdns2=inputbox("Enter Secondary DNS server IP address")
' create new server directory for KS.cfg file
strDirectory = strPath & strhostname
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(strDirectory)
' create new text file and read contents of template file
Set objFSO = CreateObject("Scripting.FileSystemObject")
strExt = objFSO.GetExtensionName(strKS)
Set objTextFile = objFSO.OpenTextFile(strKS, ForReading)
strText = objTextFile.ReadAll
objTextFile.Close
' find office code
strOffice=Mid(strhostname,3,3)
' link office code to a timezone
Select Case stroffice
Case "abu"
strTimezone="Asia/Muscat"
Case "alm"
strTimezone="Asia/Almaty"
Case "ams"
strTimezone="Europe/Amsterdam"
Case "bah"
strTimezone="Asia/Bahrain"
Case "bak"
strTimezone="Asia/Baku"
Case "bar"
strTimezone="Europe/Madrid"
Case "ber"
strTimezone="Europe/Berlin"
Case "bru"
strTimezone="Europe/Brussels"
Case "bud"
strTimezone="Europe/Budapest"
Case "cai"
strTimezone="Africa/Cairo"
Case "dus"
strTimezone="Europe/Berlin"
Case "eur"
strTimezone="Europe/London"
Case "fra"
strTimezone="Europe/Berlin"
Case "gen"
strTimezone="Europe/Zurich"
Case "kie"
strTimezone="Europe/Kiev"
Case "lon"
strTimezone="Europe/London"
Case "mad"
strTimezone="Europe/Madrid"
Case "mil"
strTimezone="Europe/Rome"
Case "mos"
strTimezone="Europe/Moscow"
Case "mun"
strTimezone="Europe/Berlin"
Case "par"
strTimezone="Europe/Paris"
Case "pra"
strTimezone="Europe/Prague"
Case "riy"
strTimezone="Asia/Riyadh"
Case "rom"
strTimezone="Europe/Rome"
Case "sto"
strTimezone="Europe/Oslo"
Case "stp"
strTimezone="Europe/Moscow"
Case "vie"
strTimezone="Europe/Vienna"
Case "war"
strTimezone="Europe/Warsaw"
Case "zur"
strTimezone="Europe/Zurich"
End Select
' replace variables with inputs
strNewText = Replace(strText, strToReplacehostname, strhostname)
strNewText = Replace(strNewText, strToReplaceip, strip)
strNewText = Replace(strNewText, strToReplacemask, strmask)
strNewText = Replace(strNewText, strToReplacegw, strgw)
strNewText = Replace(strNewText, strToReplacedns1, strdns1)
strNewText = Replace(strNewText, strToReplacedns2, strdns2)
strNewText = Replace(strNewText, strToReplacetimezone, strTimezone)
strNewFile = strDirectory & "\KS." & strExt
Set objNewFile = objFSO.OpenTextFile(strNewFile, ForWriting, True)
objNewFile.Write strNewText
objNewFile.Close
' open notepad with command to launch esx script
strinfo="Boot from ESX iso and at the prompt enter the following command:"
stresx="esx ks=" & strWebsite & strhostname & "/KS.cfg ksdevice=eth0"
' Open notepad
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad", 9
' Give Notepad time to load
WScript.Sleep 500
' Do The Paste
wshShell.Sendkeys strinfo
wshShell.sendkeys "{ENTER}{ENTER}"
WshShell.SendKeys stresx