Active Directory Slideshow

  1. <# 
  2.             "SatNaam WaheGuru" 
  3.  
  4. Date: 24-Feb-2012 ; 14:31Pm 
  5. Author: Aman Dhally 
  6. Email:  amandhally@gmail.com 
  7. web:    www.amandhally.net/blog 
  8. blog:    http://newdelhipowershellusergroup.blogspot.com/ 
  9. More Info :  
  10.  
  11. Version :  
  12.  
  13.     /^(o.o)^\  
  14.  
  15.  
  16. #> 
  17.  
  18. ## make sure you have Active Directory Moudle Installed ## 
  19.  
  20. # Import Module 
  21.  
  22. Import-Module ActiveDirectory 
  23.  
  24. # Variables 
  25.  
  26.     $computer = $env:Computername    # Computername which you want to use 
  27.     $localdc = "Dc-Del"             # Chnage with ur DC 
  28.     $credentials = Get-Credential   # This should be Admin Credentials 
  29.  
  30. # AD      
  31.     $ADResult = (Get-ADComputer -Filter {cn -like $computer}  -Server "$localdc" -Credential $credentials  ).name -eq $computer  
  32.     $dclist = (Get-ADDomain -Server "$localdc" -Credential $credentials).ReplicaDirectoryServers     
  33.      
  34.     $arrDc = @() 
  35.     foreach ($obj in $dclist) { 
  36.     $nlist = $obj.Replace("`.XYZ.com","")  # Replace XYZ.com with your Domain Name 
  37.     $arrDc += $nlist 
  38.     
  39.      
  40. # If you want to remove it from AD remove -wahtif and un-commnted -confirm:$false     
  41.      
  42.     if ($ADResult -eq $true) { 
  43.      
  44.     Write-Host -ForegroundColor  Red "$computer exists in AD, I am going to remove it" 
  45.      
  46.     foreach ( $dc in $arrdc) { 
  47.         Remove-ADComputer -Identity "$computer"  -Server $dc  -Credential $credentials  -whatif  #-confirm:$false 
  48.         write-host $([char]7) 
  49.         write-Host "$computer is deleted on $dc " -ForegroundColor Green 
  50.         }     
  51.         
  52.                  
  53. ## ENd of Script##### a m a n   d h a l l y ________ 
 
Loading...
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.