Create-ADOU


posted by Richard Giles
10-06-2008

Downloads: 330
File size: 1.7kB
Views: 1,308

Embed
Create-ADOU
  1. ## ===================================================================== 
  2. ## Title       : Create-OU 
  3. ## Description : Create an Active Directory Organizational Unit 
  4. ## Author      : Idera 
  5. ## Date        : 9/22/2008 
  6. ## Input       : -server  
  7. ##               -domain 
  8. ##               -OU 
  9. ##               -description 
  10. ##               -homepage 
  11. ##               -verbose  
  12. ##               -debug    
  13. ## Output      :  
  14. ## Usage       : PS> . Create-OU -server localhost:389 -domain Idera 
  15. ##                               -OU sales -description SalesHQ 
  16. ##                               -homepage http://mydomain.com/sales -v -d 
  17. ## Notes       : Adapted from Windows PowerShell Cookbook, Lee Holmes 
  18. ## Tag         : PowerShell, AD 
  19. ## Change log  : 
  20. ## ===================================================================== 
  21.  
  22. param 
  23.    [string]$server = "localhost:389"
  24.    [string]$domain = "Idera"
  25.    [string]$OU = "marketing"
  26.    [string]$description = "MarketingHQ"
  27.    [string]$homepage = "http://idera.com/marketing"
  28.    [switch]$verbose
  29.    [switch]$debug 
  30.  
  31. function main() 
  32.     if ($verbose) {$VerbosePreference = "Continue"
  33.     if ($debug) {$DebugPreference = "Continue"
  34.     Create-OU $server $domain $OU $description $homepage 
  35.  
  36. function Create-OU($server,$domain,$OU,$description,$homepage
  37.     trap [Exception]  
  38.         write-error $("TRAPPED: " + $_.Exception.Message); 
  39.         continue
  40.     
  41.  
  42.     # The domain must be pre-existing 
  43.     $domainObj = [adsi]"LDAP://$server/dc=$domain,dc=COM" 
  44.      
  45.     # Creates a domain with description and home page for properties 
  46.     $Org = $domainObj.Create("OrganizationalUnit", "OU=$OU"
  47.    $Org.Put("Description", $description
  48.    $Org.Put("wwwHomePage", $homepage
  49.    $Org.SetInfo() 
  50.  
  51. main 
Filed under: ,

Add an Active Directory Organizational Unit to a domain

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.