Sign in
|
Join PowerShell.com!
|
Help
Home
PowerTips
Ask the Experts
Forums
Webcasts
Blogs
eBookV2
Script Library
Twitter Grid
Modules
QuickClick
Scripts
Snippets
Videos
Library
»
Script Library
»
Active Directory
»
Create-ADOU
Create-ADOU
Share
|
Browse Library
Module Library
QuickClick Library
Script Library
Active Directory
BizTalk
Citrix
Clustering
Desktop
Exchange Server 2003
Exchange Server 2007
File System
Group Policy
Internet Information Server (IIS)
Local Accounts
Logs
Microsoft Office
Microsoft Team Foundation Server
MySQL
Networking
Registry
Remote Desktop Services
Remoting
Security
SharePoint
SQL Server
System Center Virtual Machine Manager
System Center Configuration Manager
System Center Operations Manager
Tutorial
Terminal Server
Using .Net
Virtual Server
VMware
Windows 7
Windows HPC
Windows Server 2000
Windows Server 2003
Windows Server 2008
Windows XP
WMI
Misc
Snippet Library
Video Library
Members Only
Tags
Active Directory
ad
Administrator
aman dhally
Computer
Deleted
DirectorySearcher
domain
Domain Controller
Exchange
Exchange 2003
Forest
fsmo
Group
local
Member
OU
Password
script
search
Security
Site
Tombstone
User
Users
View more
Previous
|
Next
|
View all files
|
View Slideshow
Download
posted by
Richard Giles
10-06-2008
Downloads: 330
File size: 1.7kB
Views: 1,308
Embed
Create-ADOU
## =====================================================================
## Title
: Create-OU
## Description : Create an Active Directory Organizational Unit
## Author
: Idera
## Date
: 9/22/2008
## Input
: -server
##
-domain
##
-OU
##
-description
##
-homepage
##
-verbose
##
-debug
## Output
:
## Usage
: PS> . Create-OU -server localhost:389 -domain Idera
##
-OU sales -description SalesHQ
##
-homepage http://mydomain.com/sales -v -d
## Notes
: Adapted from Windows PowerShell Cookbook, Lee Holmes
## Tag
: PowerShell, AD
## Change log
:
## =====================================================================
param
(
[
string
]
$server
=
"localhost:389"
,
[
string
]
$domain
=
"Idera"
,
[
string
]
$OU
=
"marketing"
,
[
string
]
$description
=
"MarketingHQ"
,
[
string
]
$homepage
=
"http://idera.com/marketing"
,
[
switch
]
$verbose
,
[
switch
]
$debug
)
function
main()
{
if
(
$verbose
) {
$VerbosePreference
=
"Continue"
}
if
(
$debug
) {
$DebugPreference
=
"Continue"
}
Create-OU
$server
$domain
$OU
$description
$homepage
}
function
Create-OU
(
$server
,
$domain
,
$OU
,
$description
,
$homepage
)
{
trap
[
Exception
]
{
write-error
$
(
"TRAPPED: "
+
$_
.
Exception.Message
);
continue
;
}
# The domain must be pre-existing
$domainObj
=
[
adsi
]
"LDAP://$server/dc=$domain,dc=COM"
# Creates a domain with description and home page for properties
$Org
=
$domainObj
.
Create
(
"OrganizationalUnit"
,
"OU=$OU"
)
$Org
.
Put
(
"Description"
,
$description
)
$Org
.
Put
(
"wwwHomePage"
,
$homepage
)
$Org
.
SetInfo
()
}
main
Filed under:
Active Directory
,
OU
Add an Active Directory Organizational Unit to a domain
Copyright 2011 PowerShell.com. All rights reserved.