Thursday 6 August 2009

New-Ou.PS1

  1. <# 
  2. .SYNOPSIS 
  3.     This script uses ADSI to add a new OU to a domain. 
  4. .DESCRIPTION 
  5.     This script creates a pointer to the domain, then 
  6.     uses the Create method to create a new OU under 
  7.     the root of the domain. 
  8. .NOTES 
  9.     File Name  : New-Ou.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell V2 CTP3 
  12. .LINK 
  13.     This script posted to: 
  14.         http://www.pshscripts.blogspot.com 
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .\New-OU.PS1' 
  17.     Created OU: PowerShell 
  18.      
  19.     distinguishedName : {OU=PowerShell,DC=cookham,DC=net} 
  20.     Path              : LDAP://ou=PowerShell,dc=Cookham,dc=Net 
  21. #> 
  22. ## 
  23. # Start of Script 
  24. ## 
  25.  
  26. #Set variables 
  27. $OuName = “PowerShell” 
  28. $Domain = [ADSI]“LDAP://dc=Cookham,dc=Net” 
  29.  
  30. # Create the OU 
  31. $Ou = $Domain.Create(”OrganizationalUnit”, “ou=” + $OuName
  32. $Ou.SetInfo() 
  33.  
  34. # Display results 
  35. "Created OU: {0}" -f $OUName 
  36. $OU 
Technorati Tags: ,,,

No comments: