Showing posts with label Get-ADDomain. Show all posts
Showing posts with label Get-ADDomain. Show all posts

Wednesday, September 5, 2012

Powershell and Active Directory: Get Your Active Directory Forest and Domain Information using Powershell.

Hi,

Sometime a situation comes when you want to know about your Active Directory Infrastructure.  That what is your AD Forest Name is, how many replica server do you have in your company,how many domain sites do you have  etc. etc.

When you get Answers you want to document all the above things for your future reference. Today a situation arise that i want to know answers about the above questions.

I know i can get all the answers by using Active Directory Module. But then i think if someone else need the same information, then what he will do?,he will do the same or he ask someone else in his team and waiting for their replies.

Then i think, why not to script it, so that everyone can get benefitted from it,.

So i write a simple script to done this task. Before running the script make sure you have RSAT tools installed.

Download Link: http://gallery.technet.microsoft.com/scriptcenter/Get-Active-Directory-5a51444a 

This script generates a HTML formatted Report file in your desktop folder.
That reports contain the information on :
  • Forest Name
  • Forest Mode
  • Forest Domains
  • Domain Naming Master
  • Schema Master
  • Global Catalog Servers
  • Forest Domain Sites
  • Domain Name
  • Domain NetBios Name
  • Domain Mode
  • PDC Emulator
  • InfraStructure Master
  • Replicated Servers
Screenshot of the script.
05-09-2012 15-40-18
Download Link: http://gallery.technet.microsoft.com/scriptcenter/Get-Active-Directory-5a51444a 

Thanks
Aman Dhally
join aman on facebook Join aman on Linkedin follow aman on Twitter

Wednesday, May 9, 2012

Powershell and Active Directory: Find Active Directory Replication Servers using Powershell.

 

Hi,

Today my IT manager give me the task to find and create the list of all "Active Directory Replication Server". First i was thought to find it using "Active Directory Sites and services" then i thought lets try to find it using PowerShell our favourite tool.

i use Get-ADDomain tool cmdlet to find the list of Replicated server.

 Make sure you have "RSAT" installed on you laptop.

Now Import the Active Directory module.

Import-Module ActiveDirectory

30-04-2012 23-21-03 

Lets run the Get-ADDomain cmdlet

It shows a lot of information regarding your current domain.  Like Forest, Child Domains, Parent Domain etc., but we are interested in "ReplicaDirectoryServers"

09-05-2012 12-56-27

we have to use Dot(.) notation to show the list of all servers in "ReplicaDirectoryServers"  property.

(Get-ADDomain).ReplicaDirectoryServers

Finally, now we have the list of all of our "ReplicaDirectoryServers" ..

09-05-2012 12-59-05 

Thanks for reading ..

Hope it may help someone...

Aman DhallY

Friday, March 2, 2012

Remove Computer Account from All Domain controllers using PowerShell


Hi,

If you are using Active Directory environment in you infrastructure then you does the one thing for sure , remove / add computers to the domain.

Some times when you format user computer and add it again to the Domain it gives an error that "Computer Already exists in the domain". Or you can say that you have multiple remote offices and syncing / replication between those  all DC's are slow  and you need to delete that computer from All DC including the local and remote domain Controllers.

I wrote this small script which delete the provided "computer" in to all DC which is on you replicated Server List. Before running this script make sure you have "Active Directory" module installed.

This script works for me and hope this works for you too.

You can Download the script from here : http://gallery.technet.microsoft.com/scriptcenter/Remove-Computer-Account-326f1e22

#########################################################
## make sure you have Active Directory Moudle Installed ##
# Import Module
Import-Module ActiveDirectory
# Variables
       $computer = $env:Computername     # Computername which you want to use
       $localdc = "Dc-XXXX"               # Chnage with ur local DC
       $credentials = Get-Credential   # This should be Admin Credentials
# AD  
       $ADResult = (Get-ADComputer -Filter {cn -like $computer}  -Server "$localdc" -Credential $credentials  ).name -eq $computer
       $dclist = (Get-ADDomain -Server "$localdc" -Credential $credentials).ReplicaDirectoryServers   
       $arrDc = @()
       foreach ($obj in $dclist) {
       $nlist = $obj.Replace("`.XYZ.com","")  # Replace XYZ.com with your Domain Name
       $arrDc += $nlist
       }
      
# If you want to remove it from AD remove -wahtif and un-commnted -confirm:$false
      
       if ($ADResult -eq $true) {      
       Write-Host -ForegroundColor  Red "$computer exists in AD, I am going to remove it"
       foreach ( $dc in $arrdc) {
              Remove-ADComputer -Identity "$computer"  -Server $dc  -Credential $credentials  -whatif  #-confirm:$false
              write-host $([char]7)
              write-Host "$computer is deleted on $dc " -ForegroundColor Green
              }     
              }
                          
## ENd of Script##### a m a n   d h a l l y ________                
02-03-2012 15-35-04

You can Download the script from here : http://gallery.technet.microsoft.com/scriptcenter/Remove-Computer-Account-326f1e22

Thanks for Reading.
New Delhi PowerShell User Group
Aman Dhally