Linux
Apache
MySQL
PHP

CSS
XHTML1.1
XML/RSS

Creative Commons

2006-01-24 00:00:00

More scripts and project FileFly

Well I had said before that I was writing some scripts at work. I decided to share them with you. They both are vbscripts. The first one is to change a server's TCP/IP settings. This is useful for statically configured servers when your environment (DNS servers, WINS servers, DNS zones) changes. The second script is for remapping client printers. This is useful when you move printers to a new print server and don't want to make 1000 clients manually remap their printers. Both scripts are commented, so you should be able to figure out what's happening.
On Error Resume Next '--------------------------------------------------------------------------- ' Author: Kevin J. Slonka '--------------------------------------------------------------------------- ' Description: This script sets many TCP/IP settings, such ' as the DNS servers, WINS servers, DNS domain, DNS ' suffixes, DNS registration, NETBIOS, and LMHOSTS. '--------------------------------------------------------------------------- '--------------------------------------------------------------------------- ' Variables '--------------------------------------------------------------------------- strComputer = "." arrDNSServers = Array("192.168.1.1", "192.168.1.2", "192.168.1.3") strWINSPrimaryServer = "192.168.1.1" strWINSSecondaryServer = "192.168.1.2" strDNSDomain = "" arrNewDNSSuffixSearchOrder = Array("ad.foo.com", "foo.com", "corp.foo.com") blnFullDNSRegistrationEnabled = True blnDomainDNSRegistrationEnabled = False strNETBIOS = 1 ' 0=Enabled via DHCP, 1=Enabled, 2=Disabled blnWINSEnableLMHostsLookup = False strDir = "\\server1\share" strFile = "\NetUpdates.csv" Const FORAPPENDING = 8 '--------------------------------------------------------------------------- ' Connect to the local system's WMI '--------------------------------------------------------------------------- Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") '--------------------------------------------------------------------------- ' Find all NIC's with TCP/IP enabled '--------------------------------------------------------------------------- Set colNicConfigs = objWMIService.ExecQuery _ ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") '--------------------------------------------------------------------------- ' For each NIC with TCP/IP enabled... '--------------------------------------------------------------------------- For Each objNicConfig In colNicConfigs '--------------------------------------------------------------------- ' ...grab one... '--------------------------------------------------------------------- Set objNicChanged = objWMIService.Get _ ("Win32_NetworkAdapterConfiguration.Index=" & objNicConfig.Index) '--------------------------------------------------------------------- ' ...and set the DNS/WINS servers, DNS domain, and dynamic registration '--------------------------------------------------------------------- intDNSServers = objNicChanged.SetDNSServerSearchOrder(arrDNSServers) intWINSServers = objNicConfig.SetWINSServer(strWINSPrimaryServer, _ strWINSSecondaryServer) intSetDomain = objNicConfig.SetDNSDomain(strDNSDomain) intDynReg = objNicConfig.SetDynamicDNSRegistration _ (blnFullDNSRegistrationEnabled, blnDomainDNSRegistrationEnabled) intNetBIOS = objNicConfig.SetTCPIPNetBIOS(strNETBIOS) Next '--------------------------------------------------------------------------- ' Since DNS suffixes and disabling LMHOSTS cannot be set on a per NIC basis, ' this must be done globally '--------------------------------------------------------------------------- Set objNetworkSettings = _ objWMIService.Get("Win32_NetworkAdapterConfiguration") intSetSuffixes = _ objNetworkSettings.SetDNSSuffixSearchOrder(arrNewDNSSuffixSearchOrder) intEnableWINS = objNetworkSettings.EnableWINS(False, _ blnWINSEnableLMHostsLookup) '--------------------------------------------------------------------------- ' Write the results to a logfile '--------------------------------------------------------------------------- Set objFSO = CreateObject("Scripting.FileSystemObject") Set WshNetwork = WScript.CreateObject("WScript.Network") Set objTextFile = objFSO.OpenTextFile _ (strDir & strFile, FORAPPENDING, True) objTextFile.WriteLine(WshNetwork.ComputerName & "," & intDNSServers & "," _ & intWINSServers & "," & intSetDomain & "," & intDynReg & "," & intNetBIOS _ & "," & intSetSuffixes & "," & intEnableWINS) objTextFile.Close ' END On Error Resume Next '--------------------------------------------------------------------------- ' Author: Kevin J. Slonka '--------------------------------------------------------------------------- ' Description: This script creates a collection of the user's installed ' printers, removes all printers, then checks the collection for tag numbers ' and connects to the printer on the new server. '--------------------------------------------------------------------------- '--------------------------------------------------------------------------- ' Connect to the local machine's WSH and grabs the network configuration '--------------------------------------------------------------------------- Set objNetwork = WScript.CreateObject("WScript.Network") '--------------------------------------------------------------------------- ' Create a collection of the installed printers '--------------------------------------------------------------------------- Set colPrinters = objNetwork.EnumPrinterConnections '--------------------------------------------------------------------------- ' Cycle through all installed printers and remove them if they are from ' OLDPRINTSRV '--------------------------------------------------------------------------- For i = 0 to colPrinters.Count -1 Step 2 If inStr(UCASE(colPrinters.Item(i + 1)),"OLDPRINTSRV") Then objNetwork.RemovePrinterConnection colPrinters.Item(i + 1), forced, updateProfile End If Next '--------------------------------------------------------------------------- ' For each originally installed printer, extract the printer name and ' reinstall it using the new name and server '--------------------------------------------------------------------------- For i = 0 to colPrinters.Count -1 Step 2 If inStr(UCASE(colPrinters.Item(i + 1)),"PRN1") Then objNetwork.AddWindowsPrinterConnection("\\PRINTSRV2\PRN1") ElseIf inStr(UCASE(colPrinters.Item(i + 1)),"PRN2") Then objNetwork.AddWindowsPrinterConnection("\\PRINTSRV2\PRN2") ElseIf inStr(UCASE(colPrinters.Item(i + 1)),"PRN3") Then objNetwork.AddWindowsPrinterConnection("\\PRINTSRV2\PRN3") ElseIf inStr(UCASE(colPrinters.Item(i + 1)),"PRN4") Then objNetwork.AddWindowsPrinterConnection("\\PRINTSRV2\PRN4") ElseIf inStr(UCASE(colPrinters.Item(i + 1)),"PRN5") Then objNetwork.AddWindowsPrinterConnection("\\PRINTSRV2\PRN5") End If Next ' END

My post would not be complete if I didn't tell you about project FileFly. You must be wondering, what is project FileFly? Well, a co-worker (whose name I will withhold) and I were further cleaning up the comm room. I needed to move two servers from one rack to another, which was across the room. So I shut them down, we undid the cabling, then racked it in it's new place. Then I looked at the original rack and saw one lonely server. I got mad. We are so close to getting this rack emptied. But the server left holds most of the company's version-controlled files. So, it's a pretty important server. Too bad, it's moving too. I don't care that it's still working hours. The server has redundant NIC's and redundant power. So, it was time for some fun. We ran extra long power and network cables from the other side of the room. I unplugged one power cable and one network cable. We hooked up the extra long cables, unplugged the original cables, unracked it, and set it on a chair in the middle of the floor. We took the rack kit out of the original rack and put it in the new rack, racked the server, and hooked it up like it never moved. Thus, project FileFly was complete. We moved a server from one side of the comm room to the other side of the comm room in the middle of the day without interruption.

Back

1 comments


2015-03-01 22:32:07


Anonymous says...
Doesn't work

Post a comment!

Name:
Comment: