我正在運行VBScript以在數百臺Windows 2000或Windows 2003主機上顯示DNS和WINS設置。腳本完成後,我想一眼就知道是否有服務器無法運行腳本/無法連接。 (我正在尋找類似的PowerShell catch
塊,如果可能的東西)在輸出中顯示任何失敗的服務器
的腳本如下
Const FILEPATH = "C:\users\"
'Get the input file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fsoFile = FSO.GetFile(FILEPATH & "servers.txt")
strFilePath = fsoFile.Path
Set fsoInput = FSO.OpenTextFile(strFilePath, 1)
Do While Not fsoInput.AtEndOfStream
ComputerName = fsoInput.ReadLine
Call showdnswins(ComputerName)
Loop
Sub showdnswins(ComputerName)
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2")
Set config = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each conf In config
WScript.Echo vbNewLine, "Host name is " & conf.dnshostname
WScript.Echo "WINS Primary is " & conf.winsprimaryserver
WScript.Echo "WINS Secondary is " & conf.winssecondaryserver
For Each strDNSServer In conf.DNSServerSearchOrder
WScript.Echo "DNS order is " & strDNSServer
Next
Next
End Sub
目前任何故障是未報告,並確定他們出數百臺服務器的耗時。