Returns the members of an Active Directory group

'Returns the members of an Active Directory group name Testgroup

On Error Resume Next
Set objGroup = GetObject("LDAP://cn=Testgroup,dc=Home,dc=com")
objGroup.GetInfo

arrMemberOf = objGroup.GetEx("member")

WScript.Echo "Members:"
For Each strMember in arrMemberOf
    WScript.echo strMember
Next

' End of Script

***Share your comments about the post***

Lists all the 'MembersOf' tab of a Computer object

' Lists all the 'MembersOf' tab of a Computer object
' Example: Below script will list the 'memberof' tab of Testserver1 object

On Error Resume Next

Set objGroup = GetObject _
  ("ldap://CN=Testserver1,OU=Country,DC=Home,DC=com/")
objGroup.GetInfo

arrMemberOf = objGroup.GetEx("memberof")

WScript.Echo "MembersOF:"
For Each strMember in arrMemberOf
    WScript.echo strMember
Next

' End of Script

***Share your comments about the post***

Creation of Global Security groups in Active Directory

' Creation of Global secutiry Groups in domain
' This Script has been successfully tested in Windows 2003 AD
Set objRootDSE = GetObject("ldap://RootDSE/")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Groups.txt",1)

Set objOU = GetObject("ldap://OU=Test/,"& StrDNSDomain)

Do While objFile.AtEndOfStream = False
strGroup = objFile.ReadLine
Set objGroup = objOU.Create("Group", "cn="& StrGroup)

objGroup.Put "sAMAccountName", StrGroup
objGroup.SetInfo
Set ObjGroup = nothing
Loop
Wscript.echo "Done"

' End of Script

***Share your comments about the post***

VBScript to check the Service Status and Startup Type

' Description  : This script will display the Service status and startup type in a Excel file
' Instructions : Create a text file by name servers.txt in C: drive with the server names
'                which u need to check the Service status and startup type. Output will
'                be an excel file which will be saved in C: drive with file name
'                as "Services_<date> <time>.xls"


Const Reading = 1

Dim objExcel, objWorksheet, objWorkbook, objRange
Dim objNtpad, ofjfile, inSvr, strSavefile, strDate, strTime
Dim strComputer

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)

Set objNtpad = CreateObject("Scripting.FileSystemObject")
Set objFile = objNtpad.OpenTextFile("C:\servers.txt", Reading)

inSvr = InputBox("Please enter name of the Service: Note: Enter the Exact Service name its Case sensitive", _
                  "Create File")

On Error Resume Next
Set objexcel=CreateObject("Excel.application")
If(number <> 0) Then
  On Error Goto 0
  WScript.Echo "Excel application not found"
  WScript.Quit
End If

objworksheet.cells(1,1) = "Servername"
objworksheet.cells(1,2) = "Status"
objWorksheet.cells(1,3) = "Startup Type"
objWorksheet.cells(1,3) = "Remarks"
objworksheet.range("A1:D1").font.size= 12
objworksheet.range("A1:D1").font.bold= True
objWorksheet.range("A1:D1").interior.colorindex= 33
objExcel.Columns.Borders.ColorIndex=56

strDate= Replace(Date,"/","-")
strTime= Replace(Time,":","-")
strSavefile = "C:\Services_" & strDate & " " & strTime & ".xls"

x = 2
Do
strComputer = objfile.ReadLine

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery("Select * From Win32_Service")

objworksheet.cells(x,1).value = strComputer

For Each objService in colServices
 If objservice.name = inSvr Then
   If objservice.state = "Running" Then
    objworksheet.Cells(x, 2) = "Running"
    objWorksheet.Cells(x, 3) = objservice.startmode
    objWorksheet.cells(x, 4) = ""
    Exit For
   Else
    objworksheet.Cells(x, 2) = "Not Running"
    objWorksheet.Cells(x, 3) = objservice.startmode
    objWorksheet.cells(x, 4) = ""
  Exit For
   End If
 Else
   objWorksheet.cells(x, 4) = "Service not found"
 End If

Next
 x = x + 1


Loop Until objfile.AtEndOfStream = True
  

Set objrange = objWorksheet.Usedrange
objrange.entirecolumn.autofit()

objworkbook.SaveAs strSavefile

WScript.Echo "Excel file has been saved in C:\Services_" & strDate & " " & strTime & ".xls"

objExcel.Application.Quit

Set objExcel = Nothing
Set objworksheet = Nothing
Set objWMIservice= Nothing
Set objrange = Nothing
Set objFile = Nothing
Set objNtpad = Nothing
Set inSvr = Nothing

' End of script



***Share your comments about the post***

VBScript to find Citrix Connection Disconnection timeout settings

' This script has been tested in Citrix PS4.0 environment

On Error Resume next
Const reading =1
Const HKEY_LOCAL_MACHINE = &H80000002
Set StdOut = WScript.StdOut

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Add
Set objWorksheet = objExcel.Worksheets(1)
objexcel.Visible = True
objexcel.DisplayAlerts = false

objworksheet.cells(1,1) = "ServerName"
objworksheet.cells(1,2) = "User Connection[Mins]"
objworksheet.cells(1,3) = "User Disconnection[Mins]"
objworksheet.cells(1,4) = "User Idle Timeout[Mins]"
objworksheet.cells(1,5) = "Broken or Timeout session"
objworksheet.cells(1,6) = "Reconnect Status"
objworksheet.cells(1,7) = "Shadowing"
objworksheet.cells(1,8) = "Encryption Level"

objworksheet.range("A1:H1").font.size=10
objworksheet.range("A1:H1").font.bold= True
objworksheet.range("A1:H1").interior.colorindex= 33

objexcel.Columns.Borders.ColorIndex=56


Set objFS= CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.OpenTextFile("C:\servers.txt", reading)

x=2

Do

strComputer= objFile.ReadLine
objworksheet.cells(x,1) = strcomputer

Set oReg= GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")


strKeyPath = "SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\ICA-tcp"


'---------------------------------------------------------------------------------
'Checking for Connection, Disconnection, Idle Timeout Settings
'---------------------------------------------------------------------------------
strfInheritMaxSessiontime = "fInheritMaxSessionTime"
strConnectionTime = "MaxConnectionTime"

strfInheritMaxDisconnectionTime = "fInheritMaxDisconnectionTime"
strDisconnectionTime = "MaxDisconnectionTime"

strfInheritMaxIdleTime = "fInheritMaxIdleTime"
strIdletimeout = "MaxIdleTime"


oReg.GetDWORDvalue HKEY_LOCAL_MACHINE,strKeyPath,strfInheritMaxSessiontime,dwValueCon1
oReg.GetDWORDvalue HKEY_LOCAL_MACHINE,strKeyPath,strConnectionTime,dwValueCon

oReg.GetDWORDvalue HKEY_LOCAL_MACHINE,strKeyPath,strfInheritMaxDisconnectionTime,dwValueDiscon1
oReg.GetDWORDvalue HKEY_LOCAL_MACHINE,strKeyPath,strDisconnectionTime,dwValueDiscon

oReg.GetDWORDvalue HKEY_LOCAL_MACHINE,strKeyPath,strfInheritMaxIdleTime,dwValueIdle1
oReg.GetDWORDvalue HKEY_LOCAL_MACHINE,strKeyPath,strIdletimeout,dwValueIdle

'
strValIdle=dwValueIdle/60000
strValDiscon=dwValueDiscon/60000
strValCon=dwValueCon/60000


If dwValueCon1 = 1 Then
   objworksheet.cells(x,2) = "Inherit connection set"
 ElseIf strValCon = 0 Then
   objworksheet.cells(x,2) = "No Connection Timeout"
   Else
   objworksheet.cells(x,2) = strValCon
End If

Set strValCon = Nothing
Set strValCon1 = Nothing


If dwValueDiscon1 = 1 Then
   objworksheet.cells(x,3) = "Inherit Disconnection set"
 elseIf strValDiscon = 0 Then
   objworksheet.cells(x,3) = "No Disconnection Timeout"
   Else
   objworksheet.cells(x,3) = strValDiscon
End If

Set strValueDiscon1 = Nothing
Set strValDiscon = Nothing

If dwValueIdle1 = 1 Then
   objworksheet.cells(x,4) = "Inherit Idle Timeout set"
 ElseIf strValIdle = 0 Then
   objworksheet.cells(x,4) = "No Idle Timeout"
   Else
   objworksheet.cells(x,4) = strValIdle
End If

Set strValueIdle1 = Nothing
Set strValIdle = Nothing
'-------------------------------------------------------------------------------------
'Checking for broken or timeout connection
'-------------------------------------------------------------------------------------

strInheritResetBroken = "fInheritResetBroken"
strResetBroken = "fResetBroken"

oReg.GetDWORDvalue HKEY_LOCAL_MACHINE,strKeyPath,strInheritResetBroken,dwValueRbroken1
oReg.GetDWORDvalue HKEY_LOCAL_MACHINE,strKeyPath,strResetBroken,dwValueRbroken

If dwValueRbroken1 = 1 Then
   objworksheet.cells(x,5) = "Inherit User Config"
 ElseIf dwValueRbroken = 0 Then
   objworksheet.cells(x,5) = "Disconnect"
 Else
   objworksheet.cells(x,5) = "Reset"
End If

Set dwValueRbroken1 = Nothing
Set dwValueRbroken = Nothing
'-------------------------------------------------------------------------------------
'Checking for Reconnect connection
'-------------------------------------------------------------------------------------

strInheritReconnectSame = "fInheritReconnectSame"
strReconnectSame = "fReconnectSame"

oReg.GetDWORDvalue HKEY_LOCAL_MACHINE,strKeyPath,strInheritReconnectSame,dwValueRSame1
oReg.GetDWORDvalue HKEY_LOCAL_MACHINE,strKeyPath,strReconnectSame,dwValueRSame

If dwValueRSame1 = 1 Then
   objworksheet.cells(x,6) = "Inherit User Config"
 ElseIf dwValueRSame = 0 Then
   objworksheet.cells(x,6) = "From any client"
 Else
   objworksheet.cells(x,6) = "From this client only"
End If

Set dwValueRSame1 = Nothing
Set dwValueRSame = Nothing
'-------------------------------------------------------------------------------------
'Checking for Shadowing connection
'-------------------------------------------------------------------------------------

strInheritShadow = "fInheritShadow"
strShadow = "Shadow"

oReg.GetDWORDvalue HKEY_LOCAL_MACHINE,strKeyPath,strInheritShadow,dwValueShadow1
oReg.GetDWORDvalue HKEY_LOCAL_MACHINE,strKeyPath,strShadow,dwValueShadow

If dwValueShadow1 = 1 Then
   objworksheet.cells(x,7) = "Inherit User Config"
 ElseIf dwValueShadow = 0 Then
   objworksheet.cells(x,7) = "Disabled"
 ElseIf dwValueShadow = 1 Then
   objworksheet.cells(x,7) = "Input ON, Notify ON"
 ElseIf dwValueShadow = 2 Then
   objworksheet.cells(x,7) = "Input ON, Notify OFF"
 ElseIf dwValueShadow = 3 Then
   objworksheet.cells(x,7) = "Input OFF, Notify ON"
 ElseIf dwValueShadow = 4 Then
   objworksheet.cells(x,7) = "Input OFF, Notify OFF"
End If

Set dwValueShadow1 = Nothing
Set dwValueShadow = Nothing
'-------------------------------------------------------------------------------------
'Checking for Emcryption Level
'-------------------------------------------------------------------------------------

strMinEncryptionLevel = "MinEncryptionLevel"

oReg.GetDWORDvalue HKEY_LOCAL_MACHINE,strKeyPath,strMinEncryptionLevel,dwValueEncrp


If dwValueEncrp = 0 Then
   objworksheet.cells(x,8) = "None"
 ElseIf dwValueEncrp = 1 Then
   objworksheet.cells(x,8) = "Basic"
 ElseIf dwValueEncrp = 10 Then
   objworksheet.cells(x,8) = "RC5[128-bit]Login only"
 ElseIf dwValueEncrp = 20 Then
   objworksheet.cells(x,8) = "RC5[40-bit]"
 ElseIf dwValueEncrp = 30 Then
   objworksheet.cells(x,8) = "RC5[56-bit]"
 ElseIf dwValueEncrp = 40 Then
   objworksheet.cells(x,8) = "RC5[128-bit]"
End If

Set dwValueEncrp = Nothing

'-------------------------------------------------------------------------------------

x= x+1
Loop Until objFile.AtEndOfStream =true

objworksheet.columns.autofit()

objworkbook.SaveAs "C:\Citrix_Connection_Settings.xls"

Set objworkbook = Nothing
Set objworksheet = Nothing
Set objfile = Nothing

WScript.Echo "File has been saved in C:\Citrix_Connection_Settings.xls"


***Share your comments about the post***

VBScript to find out last reboot for multiple computers

' Description  : This script will display the Last reboot of the machines in a '                     Excel file
' Instructions : Create a text file by name servers.txt in C: drive with the server '                     names which u need to check the Last Reboot. Output will be '                     an excel file which will be saved in C: drive with file name as '                     "LastReboot_<date> <time>.xls"

              

Dim objExcel, objWorkbook, objWorksheet, objRange
Dim objNtpad, objFile

Const ForReading = 1


'Opening the Input file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\servers.txt", ForReading)

Set WSHShell = WScript.CreateObject("WScript.Shell")

On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "Excel application not found."
    Wscript.Quit
End If

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = FALSE

Set objWorkbook = objExcel.Workbooks.Add
Set objWorksheet = objWorkbook.Worksheets(1)


'Creating Header for the Template excel
objWorksheet.Cells(1, 1).Value = "Server Name"
objWorkSheet.Cells(1, 2).Value = "Last Rebooted Date"
objWorkSheet.Cells(1, 3).Value = "Time"

strDate= Replace(Date,"/","-")
strTime= Replace(Time,":","-")
strSavefile = "C:\LastReboot_" & strDate & " " & strTime & ".xls"

x = 2

Do
       strComputer = objFile.ReadLine
       objWorksheet.cells(x,1).value = strComputer

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
    Bootup = objOS.LastBootUpTime

NYear = Left(Bootup,4)
NMonth = Mid(Bootup,5, 2)
NDate = Mid(Bootup,7, 2)
Nhr= Mid(Bootup,9, 2)
Nmin = Mid(Bootup,11, 2)
Nsec= Mid(Bootup,13, 2)


objWorksheet.cells(x,2).value = (NMonth & "/"& NDate & "/" & NYear)
objWorksheet.cells(x,3).value = (Nhr & ":" & Nmin & ":" & Nsec)


Next
 x = x+1

 Loop Until objFile.AtEndOfStream=True

Set objrange = objWorksheet.Usedrange
objrange.entirecolumn.autofit()

objworkbook.SaveAs strSavefile

WScript.Echo "Excel file has been saved in C:\LastReboot_" & strDate & " " & strTime & ".xls"

objExcel.Application.Quit

Set objExcel = Nothing
Set objworkbook = Nothing
Set objworksheet = Nothing
Set objfile = Nothing

' End of script

VBScript to Check server / computer OS version and Service Pack information

'Below script will provide the output in Ms-Excel. Excel application is mandatory to run this script

' List Operating System and Service Pack Information

Const Reading = 1

Dim objExcel, objWorksheet, objWorkbook, objRange
Dim objNtpad, ofjfile
'Dim inSvr as String

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)

Set objNtpad = CreateObject("Scripting.FileSystemObject")
Set objFile = objNtpad.OpenTextFile("C:\servers.txt", Reading) ' You can mention the input file location

' Checking for Excel application
On Error Resume Next
Set objexcel=CreateObject("Excel.application")
If(number <> 0) Then
  On Error Goto 0
  WScript.Echo "Excel application not found"
  WScript.Quit
End If

objworksheet.cells(1,1) = "Servername"
objworksheet.cells(1,2) = "Operating System"
objworksheet.cells(1,3) = "Version: "
objworksheet.cells(1,4) = "Service Pack: "

objworksheet.range("A1:D1").font.size= 12
objworksheet.range("A1:D1").font.bold= True

x = 2

Do
strComputer = objfile.ReadLine

Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

objworksheet.cells(x,1).value = strComputer

For Each objOS in colOSes
  objworksheet.cells(x,1).value = objOS.CSName
  objworksheet.cells(x,2).value = objOS.Caption 'Name
  objworksheet.cells(x,3).value = objOS.Version 'Version & build
  objworksheet.cells(x,4).value = objOS.ServicePackMajorVersion & "." & _
   objOS.ServicePackMinorVersion
Next


 x = x + 1

Loop Until objfile.AtEndOfStream = True

Set objrange = objWorksheet.Usedrange
objrange.entirecolumn.autofit()

Set objexcel = Nothing
Set objworksheet = Nothing
Set flag = Nothing
Set objWMIservice= Nothing
Set objrange = Nothing
Set objFile = Nothing
Set objNtpad = Nothing
'Set inSvr = Nothing