Search Windows and Linux Networking

Thursday, June 23, 2011

Search for the user in Active Directory to modify using VBScript

Search for the user in Active Directory to modify user using VBScript.
        Most frequently task of Active Directory System Admin is modify user's property. such as if user Designation has been  changed,  or manager or change in address and many more resonance to modify one particular user or group of users.  This task can be accomplish by in few min with the help of vbscript.I will show you how to do that. we use our last script that search for the users with First and Last name. and then modify that user description and save that user in active directory. or you can do the same task for all users or by reading Excel file then search in active directory for the users and modify user as per given in Excel file. in next post I will also show that .for now we use our last script and make some modification to done our job.


Option Explicit
Dim adocommand, adoconnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN , strGivenNAme ,strSN, strmail, strADsPath
Dim objUser

'Setup ADO Objects.
Set adocommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOobject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

' Search entire Active Directory Domain
Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on user objects.
strFilter = "(&(objectCategory=person)(objectClass=user)(givenName=sandeep)(sn=kapadane))"

'Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName,cn,givenName,sn,mail,ADsPath"

'Constuct the LDAP syntax query
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adocommand.commandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("TimeOut") = 30
adoCommand.properties("Cache Results") = False

' Run the query

Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
  ' Retrieve values and display.
   strName = adoRecordset.Fields("sAMAccountName").Value
   strCN = adoRecordset.Fields("cn").Value
   strGivenName = adoRecordset.Fields("givenName")
   strSN = adoRecordset.Fields("sn").Value
   strmail = adoRecordset.Fields("mail").Value
   strADsPath = adoRecordset.Fields("AdsPath").Value
   Wscript.Echo "Display Name: " & strCN & ", ADsPath:" & strADsPath
   
   ' Bind object to modify
   set objUser = GetObject(strADsPath)
   objUser.Put "description","System & Network Administrator"
   objUser.SetInfo
   WScript.Echo "User " & strCN & "is modified"
   'Move to the Next Record in the recordset.
   adoRecordSet.MoveNext
Loop

'Clean up.
adoRecordSet.Close
adoConnection.Close

' Display Massage All Done

MsgBox "Done"

Wednesday, June 22, 2011

Search user in Active Directory with First and Last Name and export user information in to excel file using VBScript.

Search user in Active Directory with First and Last Name and export user information in to excel File using VBScript.

Now we will continue our script but instead of display results we export that in to the well formatted Excel File.We use same script and make some changes to allow it to write the excel file.


Option Explicit
Dim adocommand, adoconnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN , strGivenNAme ,strSN, strmail
Dim objExcel, objwb, objrange, x

Set objExcel = createObject("Excel.Application")
set objwb = objExcel.Workbooks.add
set objwb = objExcel.activeWorkBook.Worksheets(1)
objwb.Name = "User Information "

ObjExcel.Visible = True
objwb.Activate
objwb.Cells(1,1).Value = "First Name"
objwb.Cells(1,2).value = "Last Name"
objwb.Cells(1,3).value = "Dispaly Name"
objwb.Cells(1,4).value = "Login Name"
objwb.Cells(1,5).value = "Email Address"
set objrange = objExcel.Range("A1","E1")
objRange.Interior.ColorIndex = 15
objRange.font.Bold = True

x= 2


'Setup ADO Objects.
Set adocommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOobject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

' Search entire Active Directory Domain
Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on user objects.
strFilter = "(&(objectCategory=person)(objectClass=user))"

'Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName,cn,givenName,sn,mail"

'Constuct the LDAP syntax query
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adocommand.commandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("TimeOut") = 30
adoCommand.properties("Cache Results") = False

' Run the query

Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
  ' Retrieve values and display.
   strName = adoRecordset.Fields("sAMAccountName").Value
   strCN = adoRecordset.Fields("cn").Value
   strGivenName = adoRecordset.Fields("givenName")
   strSN = adoRecordset.Fields("sn").Value
   strmail = adoRecordset.Fields("mail").Value
  
   ' Write data in Excel file

   objwb.Cells(x,1).Value = strGivenName
   objwb.Cells(x,2).value = strSN
   objwb.Cells(x,3).value = strCN
   objwb.Cells(x,4).value = strName
   objwb.Cells(x,5).value = strmail

   'Move to the Next Record in the recordset.
   adoRecordSet.MoveNext
   x = x + 1
Loop

'autofit the output
 Set objRange = objwb.UsedRange
 objRange.EntireColumn.Autofit()


'Clean up.
adoRecordSet.Close
adoConnection.Close

' Display Massage All Done

MsgBox "Done"

Tuesday, June 21, 2011

Search user in Active Directory with First and Last Name using VBScript.


Search user in Active Directory with First and Last Name using VBScript.

Suppose you want all users’ data with Fist Name, Last Name, Login Name and Email address of user. Here is a VBScript that search for all users and get required information.



Option Explicit
Dim adocommand, adoconnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN , strGivenNAme ,strSN, strmail

'Setup ADO Objects.
Set adocommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOobject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

' Search entire Active Directory Domain
Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on user objects.
strFilter = "(&(objectCategory=person)(objectClass=user))"

'Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName,cn,givenName,sn,mail"

'Constuct the LDAP syntax query
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adocommand.commandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("TimeOut") = 30
adoCommand.properties("Cache Results") = False

' Run the query

Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
  ' Retrieve values and display.
   strName = adoRecordset.Fields("sAMAccountName").Value
   strCN = adoRecordset.Fields("cn").Value
   strGivenName = adoRecordset.Fields("givenName")
   strSN = adoRecordset.Fields("sn").Value
   strmail = adoRecordset.Fields("mail").Value
   WScript.Echo "First Name: " & strGivenName & ", Last Name: " & strSN  & ", User Login Name: " & strName & ", Email Address:" & strmail
   'Move to the Next Record in the recordset.
   adoRecordSet.MoveNext
Loop

'Clean up.
adoRecordSet.Close
adoConnection.Close

In this script you can make some changes If you want to search use with Fist and last name. Suppose we want to search for user whoes First name is Sandeep and Last name is kapadane. for that we have to only need to add filter on previous script. 
 
Option Explicit
Dim adocommand, adoconnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN , strGivenNAme ,strSN, strmail

'Setup ADO Objects.
Set adocommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOobject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

' Search entire Active Directory Domain
Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on user objects.
strFilter = "(&(objectCategory=person)(objectClass=user)(givenName=Sandeep)(sn=Kapadane))"

'Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName,cn,givenName,sn,mail"

'Constuct the LDAP syntax query
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adocommand.commandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("TimeOut") = 30
adoCommand.properties("Cache Results") = False

' Run the query

Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
  ' Retrieve values and display.
   strName = adoRecordset.Fields("sAMAccountName").Value
   strCN = adoRecordset.Fields("cn").Value
   strGivenName = adoRecordset.Fields("givenName")
   strSN = adoRecordset.Fields("sn").Value
   strmail = adoRecordset.Fields("mail").Value
   WScript.Echo "First Name: " & strGivenName & ", Last Name: " & strSN  & ", User Login Name: " & strName & ", Email Address:" & strmail
   'Move to the Next Record in the recordset.
   adoRecordSet.MoveNext
Loop

'Clean up.
adoRecordSet.Close
adoConnection.Close

In Next post I will show you how to export this information in Excel file.

Thursday, June 9, 2011

Clonezilla (free Norton Ghost alternative)


Clonezilla Imaging software for backup and restore partition from network

To do life easier we want to find a simple path that accomplish our task with in few time and little hard work. This will apply to every where in life. And system administrator is not the exception for that he also want to do his job with easier or reduce the time from to do his task.  For that he always try to find a software or create script that automate the task that are required.
   
            For example to setup system for user he required to OS suppose windows XP or Windows 7 or Linux and the installed other software’s and configure setting for that system that take at least 30 to 50 Min to system get up. And what if he want to setup more than 1 system suppose 30 system for that if he do his task as single system then it may be his entire day will pass to setup all 30 system and if  there are other task he have no time to complete  that so for smarter work he should go for automated task. For example he can go for network installation of OS using answer file but till he have to install other software and configure setting to each system this will defiantly reduce some time but till he do not have a time to do other pending task that are waiting for him. For so he should go for ghost (imaging software) that dump the same setting and software to other system this will reduce the his time frame and he will got time to see other task that are waiting for him. There are many software imaging and restoring partition.

  1. Symantec Corporate Ghost
  2. Acronis True Image
  3. Ping not a Ghost
  4. Clonezilla
  5. and many more

within that Symantec Corporate Ghost and  Acronis True Image required licensing menace to use them you have to pay but Ping Not a Ghost and Clonezilla are open source software and freely available to use . These all support network boot.

  In corporate Symantec Corporate Ghost and CloneZilla are most popular imaging software for network. So why not go for Clonezilla, if it done our job and it free :-)  and giving almost fetchers like multitasking and like that Symantec Ghost support.


Friday, June 3, 2011

How to Install Zabbix Agent on Windows


Installing Zabbix Agent on Windows

Download zabbix agent file from http://www.zabbix.com/download.php and unzip that.

Open command prompt from Start > Run and  then type cmd then click ok

Create new folder for zabbix agent

mkdir c:\Program Files\zabbix

Now copy zabbix_agentd.exe, zabbix_get.exe and zabbix_sender.exe from win32 folder if your OS is x86 else copy from win64 for x64 bit

From command prompt run following command  to create configuration file for zabbix_agent

Note: - change IP Address of Zabbix server instead of 192.168.73.242 . Please be sure that commands are in single line
Echo Server=192.168.73.142 > "c:\Program Files\zabbix\zabbix_agentd.conf"
Echo Hostname=%COMPUTERNAME% >> "c:\Program Files\zabbix\zabbix_agentd.conf"
 "C:\Program Files\zabbix\zabbix_agentd.exe" -c "c:\Program Files\zabbix\zabbix_agentd.conf" –i
 "C:\Program Files\zabbix\zabbix_agentd.exe" -c "c:\Program Files\zabbix\zabbix_agentd.conf" –s

Now zabbix agent service is installed and started as automatic start.

OR

You can create batch file for installing zabbix agent . batch file copy that three files from share folder, Create new directory for zabbix agent  then copy required files and install and start service you only need run that zabbix_agent_windows.bat file

@echo off
echo copying exe
net use m: \\ipaddOfShareHost\Share\zabbix_Windows_agent\zabbix_agents_1.8.5.win
mkdir "c:\Program Files\zabbix"
xcopy m:\win32 "c:\Program Files\zabbix"
net use m: /delete
echo Creating configuration for %COMPUTERNAME%...
echo Server=192.168.73.142 > "c:\Program Files\zabbix\zabbix_agentd.conf"
echo Hostname=%COMPUTERNAME% >> "c:\Program Files\zabbix\zabbix_agentd.conf"
echo Installing system service...
"c:\Program Files\zabbix\zabbix_agentd.exe" -c "c:\Program Files\zabbix\zabbix_agentd.conf" -i
echo Starting agent...
"c:\Program Files\zabbix\zabbix_agentd.exe" -c "c:\Program Files\zabbix\zabbix_agentd.conf" -s
echo Finished!
pause


Thursday, June 2, 2011

Monitoring Router or Other Devices using Simple check with Ping (ICMP) in Zabbix


Monitoring Router or Other Devices using Simple check with Ping (ICMP) in Zabbix

For ICMP check Zabbix required different utility for Ping (ICMP echo  ) that is fping. To support Zabbix to simple check you have to first install fping and set the location for fping

fping :- fping is a ping-like program which can determine the accessibility of multiple hosts using ICMP echo requests. fping is designed for parallelized monitoring of large numbers of systems, and is developed with ease of use in scripting in mind.

Install fping :-

You can install fping with following command :-

# yum install fping

Or You can install it by tarbell file



# tar -zxvf fping.tar.gz
# cd fping-2.4b2_to/
# ./configure
# make
# make check
# checkinstall
OR
# make install


Note:- Zabbix server must know where to find fping and be able to execute it.

First check the correct path of fping and then modify zabbix_server.conf file for correct path

# whereis fping
fping: /usr/local/sbin/fping

Now give necessary permission  
# ls -l /usr/local/sbin/fping
-rwxr-xr-x 1 root root 48903 Jun  2 11:01 /usr/local/sbin/fping
# chgrp zabbix /usr/local/sbin/fping
# ls -l /usr/local/sbin/fping
-rwxr-xr-x 1 root zabbix 48903 Jun  2 11:01 /usr/local/sbin/fping
# chmod 4710 /usr/local/sbin/fping
# ls -l /usr/local/sbin/fping
-rws--x--- 1 root zabbix 48903 Jun  2 11:01 /usr/local/sbin/fping

# vi /etc/zabbix/zabbix_server.conf

FpingLocation=/usr/local/sbin/fping

Now restart zabbix server service for changes take effect .

# service zabbix_server restart
Now Zabbix is ready for simple icmp check.

Now open http://ip-address/zabbix and Login to Zabbix as admin

If you have not already added host add it first before creating item

Crate New Host for Router.

To crate new host go to configuration | Hosts and Select Create Host. In New host form type the host name of Router. Basically Router and switch are SNMP supported devices so select SNMP Devices in Group field. Then type the IP Address of Router and then Save the host.

Now we have added Router to our Zabbix monitoring software but it not knowing what to check so for that we have to create item to know Zabbix what to check and using which method. We can be monitor Router using SNMP or by simply sending ping request.

 For now we check our router is live or not using simple check.

So click Item next to Route we just added and then click Crate Item. In Crate Item new form Host is already selected as your router. In description box type the description for the test. For example  Network Reachability using ping . In Type drop down box select Simple Check . In key box type icmpping. In type of information drop down menu select Numeric (float). In Units box type ms . In update interval (in Sec) change it to 60 and show value drop down menu select host status and save the item by clicking Save.

Now we have created test to check network reachability of router. Now we want zabbix have to send a mail if router is unreachable for that we have to create trigger and action. Because we have already configured action for trigger; we have to crate trigger for newly created item. So for that click on trigger next to Router we have added and click Create Trigger . In new Trigger form type the identical information that sense as what is wrong
Type that in Name field. For, example Router is down or unreachable.
In expression field click add this will open new page for condition. Click Select next to item box and then select item we just created Network Reachability using ping and then click insert and then click save.


Now when ever our router get down or unreachable Zabbix will send mail saying that Router is down or unreachable.

Wednesday, June 1, 2011

Sending test notification from Zabbix



Testing Zabbix server by sending Test Notification 

For now we have installed zabbix and configure zabbix for Mail configuration and for action. But how do we know that it is actually working. For so we have to do something that is working and then we have to manually create trouble on that zabbix will monitor that and it find that there is problem with that item. So it take action against that by sending mail to admin as we configure last time . so what we will do we add localhost in zabbix and create item to monitor /tmp/text.txt file exsit and create trigger if file not exist. After that we delete that file so trigger will execute and zabbix take action by sending notification mail to admin.
For testing purposes we have to do following tasks:-
  1. Add HOST
  2. Create Item
  3. Create Trigger
  4. Create problem

Adding HOST: - By default zabbix_server host is added and it is disable for monitoring . do not enable it. For testing, we add host manually. So to add host first of all login in to zabbix  with user name admin and default password zabbix. Then go to Configuration > Hosts and then select Create Host. In New host window type the hostname for example zabbix. In Group field windows remove zabbix_server and add Linux Server. In IP address box type the IP address 127.0.0.1 for monitor localhost and insure that status is equal to monitored is selected then click to save the host.



Create Item:- create file as /tmp/test.txt using command
# touch /tmp/test.txt
 Now next to zabbix (host we just added ) there are no item . Select item next to zabbix and select Create Item . In new item windows host equal to zabbix will already selected. Type Description “/tmp/test.txt file exists for testing” , Type equal to Zabbix agent and then type most important thing Key is equal to vfs.file.exists[/tmp/test.txt] there are many field s there but for testing purpose it is in up for us . Click Save to Save the newly created item.

Create Trigger :-  Now we crate trigger for /tmp/test.txt file. Now next to zabbix host in trigger field select trigger then click Create Trigger . In New trigger Name file give the identical name for identify . For example /tmp/test.txt file does not exist and then type {zabbix:vfs.file.exists[/tmp/test.txt].last(0)}=0 in expression field and select warning in Severity drop down list. And click Save to save our trigger.

Create Problem :- Now every thing is looking ok . Now we have to crate problem by deleting the test.txt file so that zabbix will check that there is not such file so it take the action

# rm -rf /tmp/test.txt

After few min you got an email with subject zabbix /tmp/test.txt file does not exist: Problem

Now troubleshoot the problem by create same file using command

# touch /tmp/test.txt

After few min you got another email with subject zabbix /tmp/test.txt file does not exist: OK


Configure Action on Zabbix


Configure Zabbix for Action
Last time we configure Zabbix for email parameter to use for to send email notification now we have to configure action on Zabbix server to do something upon certain conditions match.

To configure actions, open Configuration > Actions. There are no existing actions listed, so click Create Action.
.
In action windows type name for example "Send Mail" In event source select Triggers .

In Default subject:- On {HOSTNAME} {TRIGGER.NAME}: {TRIGGER.STATUS}

In Default message :- On {HOSTNAME} {TRIGGER.NAME}: {TRIGGER.STATUS}
                                   Last value: {ITEM.LASTVALUE}

                                  {TRIGGER.URL}

In Action Operations click New :-

Select send message in operation type  and send message to select  single user then click on select and then select admin and click add and click save.