Monday, January 24, 2011

List all member of a group in AD


Simple VB script to display members of a group.


Copy the below code and edit as ur requirement and save it as extension .vbs

On Error Resume Next

Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")
objGroup.GetInfo

arrMemberOf = objGroup.GetEx("member")

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



Get Last logon of user in AD


Simple powershell script to display last logon of all users.



$searcher = New-Object DirectoryServices.DirectorySearcher([adsi]"")
$searcher.filter = "(objectclass=user)"
$users = $searcher.findall()

Foreach($user in $users)
{
 if($user.properties.item("lastLogon") -ne 0)
  {
   $a = [datetime]::FromFileTime([int64]::Parse($user.properties.item("lastLogon")))
   "$($user.properties.item(`"name`")) $a"
  }
}

Script to search for all domain controller in a domain

Simple powershell script to get all domain controller details in domain.


PowerShell
$objDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()  
$objDomain.FindAllDomainControllers() | Select-Object Name 

Sunday, January 23, 2011

Troubleshooting DHCP servers

                  Microsoft gives the some basic troubleshooting steps for DHCP. Follow the below link for the steps

http://technet.microsoft.com/en-us/library/cc779112(WS.10).aspx






Thursday, January 20, 2011

DHCP Backup and Move From one server to another


If we would like to move a DHCP server to another machine.Its simple.. follow the bellow steps.
Step 1 :- In Server, navigate to a command prompt.

Step 2 :- Type the following command :netsh


Step 3 :-  Type the following command :DHCP


Step 3 :- Type the following Command: server <\\Name or IP Address >


Step 4 :-  Type the following Command: export c:\w2k3DHCPdb all


Note : - you should have local administrator permission to export data.


Import the DHCP database

1.       Copy the exported DHCP database file to the local hard disk of the Windows Server 2008-based      
computer. 

2.       Install the DHCP Role on the server. 

3.       Stop the DHCP server service on the server.  To do this, follow these steps: 

4.       Log on to the target DHCP server by using an account that is a member of the local Administrators group.

5.      Click Start, click Run, type cmd in the Open box, and then click OK. 



6.       At the command prompt, type net stop DHCPserver , and then press ENTER. You receive a"TheMicrosoft DHCP Server service is stopping. The Microsoft DHCP Server service was stopped successfully" message. 

7.      Type exit, and then press ENTER. 

8.       Delete the DHCP.mdb file under c:\windows\system32\DHCP folder. 

9.       Start the DHCP server service. 

10.       Right-click on the Command Prompt (cmd) and select run as administrator, to open the cmd prompt using elevated privileges. 

Note you should have local administrator permission to Import data.. 

11.   Type the following Command: netsh

12.   Type the following Command: DHCP

13.   Type the following Command: server <\\Name or IP Address>

10.   Type the following Command: import c:\w2k3DHCPdb

11.   Restart DHCP and verify the database has moved over properly. 


 

Monday, January 17, 2011

Active Directory - Fast Searching.


Hi,
     If u like to search Active directory as like fast. create a new shortcut, paste the below command and save it. now u able to find as much fast.

%windir%\system32\rundll32.exe dsquery.dll,OpenQueryWindow

Disable Inactive accounts - Active Directory

Friends,

Simple command to disable inactive accounts in active directory, the command dsquery.

"dsquery user -inactive 24 | dsmod user -disabled yes"


Here i have specified 24, is equal to 24 weeks. if u want to disable inactive accounts last two weeks, just u need to specify only 2.



Ports required for Domain Controller and Clients

AD communication takes place using some ports. Here i have specified some main ports

UDP Port 88 for Kerberos authentication
UDP and TCP Port 135 for domain controllers-to-domain controller and client to domain controller operations.
TCP Port 139 and UDP 138 for File Replication Service between domain controllers.
UDP Port 389 for LDAP to handle normal queries from client computers to the domain controllers.
TCP and UDP Port 445 for File Replication Service
TCP and UDP Port 464 for Kerberos Password Change
TCP Port 3268 and 3269 for Global Catalog from client to domain controller.
TCP and UDP Port 53 for DNS from client to domain controller and domain controller to domain controller.

Sunday, January 16, 2011

Enable Regedit – Disabled by Virus

Hi Friends,
If you face registry disabled issue, copy the below code and save it as .vbs, then execute it.

Option Explicit


'Declare variables
Dim WSHShell, n, MyBox, p, t, mustboot, errnum, vers
Dim enab, disab, jobfunc, itemtype


Set WSHShell = WScript.CreateObject("WScript.Shell")
p = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\"
p = p & "DisableRegistryTools"
itemtype = "REG_DWORD"
mustboot = "Log off and back on, or restart your pc to" & vbCR & "effect the changes"
enab = "ENABLED"
disab = "DISABLED"
jobfunc = "Registry Editing Tools are now "


'This section tries to read the registry key value. If not present an
'error is generated.  Normal error return should be 0 if value is
'present
t = "Confirmation"
Err.Clear
On Error Resume Next
n = WSHShell.RegRead (p)
On Error Goto 0
errnum = Err.Number


if errnum <> 0 then
'Create the registry key value for DisableRegistryTools with value 0
 WSHShell.RegWrite p, 0, itemtype
End If


'If the key is present, or was created, it is toggled
'Confirmations can be disabled by commenting out
'the two MyBox lines below


If n = 0 Then
 n = 1
WSHShell.RegWrite p, n, itemtype
Mybox = MsgBox(jobfunc & disab & vbCR & mustboot, 4096, t)
ElseIf n = 1 then
 n = 0
WSHShell.RegWrite p, n, itemtype
Mybox = MsgBox(jobfunc & enab & vbCR & mustboot, 4096, t)
End If








Web Hosting