This may sound like an odd request, if you've worked in information technology long enough, especially with SMS/ConfigMgr, you've probably gotten a lot of strange requests.
Scenario: Network switches are being replaced, any computer on the network with a NIC that has it's Speed & Duplex property set to something other than 'Auto', will fail to connect to the network and communicate with a DHCP server. Not a good thing. To further complicate this picture, even though computers were originally built with images using a NIC Speed & Duplex set to 'Auto'. Desktop support would occasionally set the NIC to 10 Mb Full in an attempt to correct network connection issues. We need to identify and correct these computers prior to the network hardware being swapped to avoid panic calls to the help desk.
Solution: Create a custom VBScript that is run on every desktop via SMS/ConfigMgr, leaving a file with a unique name and file type of '*.flg' that could be easily queried and/or used to create a collection of computers that could be corrected via automation.
Script: The information we need to locate is in the registry, further, I wanted the ability to log the script activity locally, much like SMS logging. The flag file created for inventory needed to be easy to aggregate via SQL queries. This script was tested with an Intel NIC, other manufactures may use different registry key locations.
Flag file format followed by the possible numeric values:
' flag file to be constructed as SMSEng-NIC-<SpeedDuplex>-<DriverDescription (first 5 char)>
'0 - Auto Detect
'1 - 10Mbps \ Half Duplex
'2 - 10Mbps \ Full Duplex
'3 - 100Mbps \ Half Duplex
'4 - 100Mbps \ Full Duplex
LocateNIC.vbs
' begin VBscript
Option Explicit
'On Error Resume Next
' Begin log stuff
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim strIN, strTextIn
Dim objFSO, objDictionary, objTextFile, objItem
dim strNextLine
dim i
dim FSOOut
dim Overwrite
dim Unicode
dim FileName, FileOut
Dim strFileIn
Dim strFileOut
Dim f
Dim strMsg
' End log stuff
' Flag file
Dim strFlagFile
Dim fFlag
Dim strSMSRoot
Dim strComputer
dim objReg, strKeyPath, subkey, arrSubKeys, dwValue
dim strValue
dim strDriverValue, strModeValue2
Dim strSpeedDuplex
Dim strDriverDesc
Dim strSubkey
Const HKEY_LOCAL_MACHINE = &H80000002
' log file
strSMSRoot = "C:\Program Files\sms"
strFileOut = "SMSEng-NIC.log"
' Verify/Create Folders
' Flag folder
Call VerifyCreateFolder(strSMSRoot & "\flg")
Call VerifyCreateFolder(strSMSRoot & "\flg\SMSEng-NIC")
' Delete Any Flag files...
Call DeleteFlagFiles(strSMSRoot & "\flg\SMSEng-NIC\*.flg")
' Log folder
Call VerifyCreateFolder(strSMSRoot & "\log")
Call VerifyCreateFolder(strSMSRoot & "\log\SMSEng-NIC")
' file out
Set FSOOut = WScript.CreateObject("Scripting.FileSystemObject")
Overwrite = False
Unicode = False
' start log file
' open client log file
Call OpenClientLog
strMsg = "Started Script Process..."
Call WriteClientLog (strMsg)
' flag file to be constructed as SMSEng-NIC-<SpeedDuplex>-<DriverDescription (first 5 char)>
' test
'strFlagFile = "SMSEng-NIC-0-INTEL.flg"
'Call CreateFlagFile (strFlagFile)
strComputer = "."
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "System\Currentcontrolset\Control\Class\{4D36E972-E325-11CE-BFC1-08002be10318}"
strDriverValue = "DriverDesc"
strModeValue2 = "SpeedDuplex"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
'0 - Auto Detect
'1 - 10Mbps \ Half Duplex
'2 - 10Mbps \ Full Duplex
'3 - 100Mbps \ Half Duplex
'4 - 100Mbps \ Full Duplex
' Capture Driver Description
objReg.GetStringvalue HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey, strDriverValue, strValue
strDriverDesc = strValue
strSubkey = subkey
' Capture SpeedDuplex
objReg.GetStringvalue HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey, strModeValue2, dwValue
strSpeedDuplex = CStr(dwValue & "")
' WScript.Echo " " & strModeValue2 & ": " & strSpeedDuplex
If Len(strSpeedDuplex & "") > 0 then
strFlagFile = "SMSEng-NIC-" & strSpeedDuplex & "-" & LEFT(UCASE(strDriverDesc),5) & ".flg"
Call CreateFlagFile (strFlagFile)
' log entries
strMsg = "Create Flag file: '" & strFlagFile & "'"
Call WriteClientLog (strMsg)
strMsg = "... subkey: '" & strSubkey & "' Full Driver Description: '" & strDriverDesc & "'"
' wscript.echo "strMsg: " & strMsg
Call WriteClientLog (strMsg)
Else
strMsg = "... subkey: '" & strSubkey & "' Full Driver Description: '" & strDriverDesc & "'"
Call WriteClientLog (strMsg)
' wscript.echo "strMsg: " & strMsg
End If
' End If
Next
' Create Flag file subs
Sub CreateFlagFile (strFlagFile)
' strFileOut = strSMSRoot & "\log\SMSEng-NIC.log"
' On Error Resume Next
Set fFlag = FSOOut.OpenTextFile(strSMSRoot & "\flg\SMSEng-NIC\" & strFlagFile, ForAppending, True)
fFlag.Write Now()
fFlag.Close
End Sub
' Begin log subs
Sub OpenClientLog
On Error Resume Next
Set f = FSOOut.OpenTextFile(strSMSRoot & "\log\SMSEng-NIC\" & strFileOut, ForAppending, True)
End Sub
Sub CloseClientLog
On Error Resume Next
f.Close
End Sub
Sub WriteClientLog (LineOut)
On Error Resume Next
f.Write Now() & "," & LineOut & vbCRLF
End Sub
' End log subs
Sub VerifyCreateFolder(fldr)
Dim lfso, lmsg, lf
Set lfso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
If (lfso.FolderExists(fldr)) Then
' msg = fldr & " exists."
Else
' msg = fldr & " doesn't exist."
Set lf = lfso.CreateFolder(fldr)
End If
' ReportFolderStatus = msg
End Sub
Sub DeleteFlagFiles(FlagFiles)
Dim lfso, lmsg, lf
Set lfso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
lfso.DeleteFile(FlagFiles)
End Sub
' End VBscript
Hopefully this gives you some ideas for your own 'special' requests. The next blog will illustrate how to fix these NIC's, with automation, of course. :)