Categories
Domain Migration

VBSCript : Force Automatic DNS config on DHCP enabled NIC

Useful for AD / DNS migrations, this script will scan a text file containing a list of PC names and will interrogate each one to see if it is DHCP enabled on each NIC. If DHCP is enabled it will delete any manually assigned DNS servers and configure the NIC to automatically get the DNS servers via DHCP.

‘ Script to scan PCs for network cards that use DHCP and remove
‘ all manually set DNS servers for those cards only

On Error Resume Next

Const ForReading = 1

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objTextFile = objFSO.OpenTextFile _
    (“hosts.txt”, ForReading)

Do Until objTextFile.AtEndOfStream
    strComputer = objTextFile.Readline
    Wscript.Echo “Processing ” & strComputer
Set objWMIService = GetObject(“winmgmts:” _
  & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)
Set colNicConfigs = objWMIService.ExecQuery _
  (“SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True”)
 
For Each objNicConfig In colNicConfigs
    WScript.Echo VbCrLf & ”  Network Adapter ” & objNicConfig.Index & _
      VbCrLf & ”    ” & objNicConfig.Description & VbCrLf
    If objNicConfig.DHCPEnabled Then
                intSetDNSServers = _
                objNicConfig.SetDNSServerSearchOrder
    Else
        WScript.Echo “DHCP not enabled on this card”
    End If
Next
Loop

Categories
VBScript

VBScript : Find Files By Owner

The following code will list all files which a particular user owns, you will need to ‘pipe’ its output to a file using the following command: cscript.exe find-own.vbs > files.txt

Set objShell = CreateObject (“Shell.Application”)
Set objStartFolder = objShell.Namespace (“N:\”)
Set objFSO = CreateObject(“Scripting.FileSystemObject”)

strUsername = “NETBIOSNAME\sAMAccountName”
oFolder = “N:\”

Dim arrHeaders(13)

ShowSubfolders objFSO.GetFolder(oFolder)

Sub ShowSubFolders(Folder)
On Error Resume Next
    For Each Subfolder in Folder.SubFolders
        Set oNsp = objShell.Namespace(Subfolder.Path)
        ‘Dim arrHeaders(13)
        For i = 0 to 13
            arrHeaders(i) = oNsp.GetDetailsOf (oNsp.Items, i)
        Next

        For Each strFileName in oNsp.Items
            If LCASE(oNsp.GetDetailsOf (strFileName, 8)) = LCASE(strUsername) Then
       
            Wscript.Echo Subfolder.Path & “\” & strFilename & “,” & arrHeaders(1) & “,” & Replace(oNsp.GetDetailsOf (strFileName, 1),”,”,””)
            End If
        Next
    ShowSubFolders Subfolder
    Next
End Sub

Categories
VBScript

VBScript ; Ping Test

The following code will ping a semi-colon de-limited list of computers, displaying output on the command windows. Save the file as ping.vbs and call using the following command: cscript.exe ping.vbs

Set WshShell = CreateObject(“WScript.Shell”)

strPCs = “host1;host2”
strPCs = Split(strPCs,”;”)

For each PC in strPCs
    PingTest(PC)
Next

Sub PingTest(strComputer)
    Set objScriptExec = WshShell.Exec(“ping ” & strComputer)
    Do While Not objscriptexec.Stdout.AtEndOfStream
        str = objscriptexec.Stdout.ReadLine   
        If InStr(1,str,”Lost = 0″,1) > 0 Then
            WScript.Echo(”   ” & strComputer & “: OK – 100%”)
        ElseIf    InStr(1,str,”Lost = 1″,1) > 0 Then
            WScript.Echo(”   ” & strComputer & “: FAIL – 75%”)
        ElseIf    InStr(1,str,”Lost = 2″,1) > 0 Then
            WScript.Echo(”   ” & strComputer & “: FAIL – 50%”)
        ElseIf    InStr(1,str,”Lost = 3″,1) > 0 Then
            WScript.Echo(”   ” & strComputer & “: FAIL – 25%”)
        ElseIf InStr(1,str,”Lost = 4″,1) > 0 Then
            WScript.Echo(”   ” & strComputer & “: FAIL – 0%”)
        End If
    Loop
End Sub

Categories
Windows Server 2003

Manual Windows Defender Update

If, like many, you have configured your Windows Firewall / any other 3rd party firewall to block all outgoing traffic you will find that Windows defender will be unable to update unless you allow port 80/443 (HTTP/HTTPS) for executable svchost.exe. However, this is a core Windows executable, and therefore you may wish to block this as it isn’t used by Windows Defender alone.

The solution therefore is to manually update your windows defender definitions using the following URLs:

 

The latest x86 / 32bit Windows Defender Updates are always available using this URL:

http://go.microsoft.com/fwlink/?linkid=70631

For x64 versions of Windows, use the following URL:

http://go.microsoft.com/fwlink/?linkid=70632

Finally, for Itanium version of Windows use the following URL:

http://go.microsoft.com/fwlink/?linkid=70633

Categories
Windows Server 2003

VBScript; List AD Group Members

The script below will list all members of a particular group within AD.

The script should be called as follows from a  command window: cscript.exe script_name.vbs > Group-Members.txt

This will ‘pipe’ the results into a text file in the same folder as the vbs file.

 

‘—————————- Begin Copy Here

Dim arrNames()

intSize = 0

Set objGroup = GetObject(“LDAP://CN=Merchandising,OU=Security Groups,OU=UK,DC=mydom,DC=com”)

For Each strUser in objGroup.Member
    Set objUser =  GetObject(“LDAP://” & strUser)
    ReDim Preserve arrNames(intSize)
    arrNames(intSize) = objUser.CN
    intSize = intSize + 1
Next

For i = (UBound(arrNames) – 1) to 0 Step -1
    For j= 0 to i
        If UCase(arrNames(j)) > UCase(arrNames(j+1)) Then
            strHolder = arrNames(j+1)
            arrNames(j+1) = arrNames(j)
            arrNames(j) = strHolder
        End If
    Next
Next

For Each strName in arrNames
    Wscript.Echo strName
Next

‘—————————- End Copy Here

Categories
Windows Server 2003

Run Command Prompt as System / Computer Account

This simple, but very useful task is handy for testing kerberos and machine account permissions. From a command prompt run the following command:

at 17:00 /interactive cmd

Where 17:00 is the time now +1 minute. Wait 1 minute and then the command prompt will pop-up.

Categories
Windows Server 2003

Ftp.exe –  Netout :Connection reset by peer :FIX

When using the Windows XP Firewall several of our users encountered the following error when using ftp.exe:

 

> Netout :Connection reset by peer Connection closed by remote host.

 

Initially we tried creating exceptions for this application, but this proved inaffective.

 

The solution was to increase the  FTP Buffer window using the follwoing command:

 

ftp.exe -w:12288

 

This increases the FTP buffer from 4MB to 12MB – the FTP process is significantly faster and does not drop out with the above error.

Categories
Windows Server 2003

MSDTC Could Not Correctly Process a DC Promotion/Demotion Event: Fix

 

Event Type:    Warning
Event Source:    MSDTC
Event Category:    MSDTC Proxy
Event ID:    53258
Date:        19/11/2008
Time:        11:35:49
User:        N/A
Computer:    ESDC02
Description:
MS DTC could not correctly process a DC Promotion/Demotion event. MS DTC will continue to function and will use the existing security settings. Error Specifics: d:\nt\com\complus\dtc\dtc\adme\uiname.cpp:9351, Pid: 1252
No Callstack,
 CmdLine: C:\WINDOWS\system32\msdtc.exe

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
Data:
0000: 05 00 07 80               …?   

 

 

Event Type:    Warning
Event Source:    MSDTC
Event Category:    SVC
Event ID:    53258
Date:        19/11/2008
Time:        11:35:49
User:        N/A
Computer:    ESDC02
Description:
MS DTC could not correctly process a DC Promotion/Demotion event. MS DTC will continue to function and will use the existing security settings. Error Specifics: %1

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

 

To resolve this issue modifiy the following registry key as detailed below:

HKLM\Software\Microsoft\MSDTC

Grant Advanced Permissions of Set Value and Create Subkey to the ‘NETWORK SERVICE’ account.

Categories
VBScript

VBScript ; Set UserPreferencesMask Binary Registry Key

Set UserPreferencesMask Binary Registry Key

 

An ideal solution for configuring display options for ‘best performance’ on Citrix and Terminal Servers:

 

 

Simply add the following code to an existing VB logon script or create a new one to run along side you exusting scrip:

Const HKEY_CLASSES_ROOT  = &H80000000
Const HKEY_CURRENT_USER  = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS         = &H80000003

Set WshShell = CreateObject(“WScript.Shell”)

‘Lookup User Account Name and Logon Domain Name
Set objNetwork = CreateObject(“Wscript.Network”)
currentDomain = objNetwork.UserDomain
currentUser = objNetwork.UserName

Set wmiLocator = CreateObject(“WbemScripting.SWbemLocator”) ‘ Object used to get StdRegProv Namespace
Set wmiNameSpace = wmiLocator.ConnectServer(objNetwork.ComputerName, “root\default”) ‘ Registry Provider (StdRegProv) lives in root\default namespace.
Set objRegistry = wmiNameSpace.Get(“StdRegProv”)

uBinary = Array(&H90,&H12,&H01,&H80)
cmd = objRegistry.SetBinaryValue(HKEY_CURRENT_USER, “Control Panel\Desktop”, “UserPreferencesMask”, uBinary) 

The changes will be applied at second logon (ie first logon the change is written to the users hive, at second logon this setting will be used) 

Categories
VBScript

VBScript ; Find User Group Memberships (+ Nested groups)

VBScript ; Find User Group Memberships (including Nested groups)

 

This fast, simple logon script will enumerate a user accounts group memberships, including nested groups.

 

‘Obtain fqdn of domain
Set oRoot = GetObject(“LDAP://rootDSE”)
Set oDomain = GetObject(“LDAP://” & oRoot.Get(“defaultNamingContext”))
fqDomain = oRoot.Get(“defaultNamingContext”)

‘Obtain netbios username, computername and domainname
Set objNetwork = CreateObject(“Wscript.Network”)
currentDomain = objNetwork.UserDomain
currentUser = objNetwork.UserName
strComputerName = objNetwork.ComputerName


‘————————————————- Main Program

‘Find user DistingishedName and bind to user object to find nested group memberships
uCN = findDN
Set objUser=GetObject(“LDAP://” & uCN)

If IsMember(“Domain Admins”) Then
MsgBox “User is a member of the domain admins group….”
‘Perform required functions here.
End If


‘————————————————- Functions

Function IsMember(grpName) ‘Function to find groups to which user is a *DIRECT* member of.
If IsEmpty(grpList) Then
Set grpList = CreateObject(“Scripting.Dictionary”)
grpList.CompareMode = TextCompare

Set colGroups = objUser.Groups
For Each objGroup in colGroups
If NOT CBool(grpList.Exists(objGroup.CN)) Then
grpList.Add objGroup.CN, “-“
GetNested(objGroup)
End If
Next
End If
IsMember = CBool(grpList.Exists(grpName))
End Function

Function GetNested(objGroup) ‘New Recursive Nested Group Membership Function.
On Error Resume Next
colMembers = objGroup.GetEx(“memberOf”)
For Each strMember in colMembers
If NOT strMember = “” Then
strPath = “LDAP://” & strMember
Set objNestedGroup = GetObject(strPath)
If NOT CBool(grpList.Exists(objNestedGroup.CN)) Then
grpList.Add objNestedGroup.CN, “-“
GetNested(objNestedGroup)
End If
End If
Next
End Function

Function findDN ‘Funtion to find DistinguishedName of User Object using sAMAccountName
Set objConnection = CreateObject(“ADODB.Connection”)
objConnection.Open “Provider=ADsDSOObject;”

Set objCommand = CreateObject(“ADODB.Command”)
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
“<LDAP://” & fqDomain & “>;(&(objectCategory=” & “User” & “)” & _
“(samAccountName=” & currentUser & “));samAccountName,distinguishedName;subtree”

Set objRecordSet = objCommand.Execute

If objRecordset.RecordCount = 0 Then
WScript.Quit(0)
Else
findDN = objRecordSet.Fields(“distinguishedName”).Value
objConnection.Close
End If
End Function