search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell, Windows Server | No Comment | 4,597 views | 18/08/2009 11:53

This is my simple Powershell script to create organizational units with Powershell.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function Add-CustomerOU
{
param ($CustomerID, $CustomerOU)
 
    $CheckCustomerOU = Check-CustomerOU -CustomerID "$CustomerID" -CustomerOU "$CustomerOU"
 
    If($CheckCustomerOU.Status -eq "0")
    {
        $FQDN = (Get-ADInfo).FQDN
        $CustomerOU = [ADSI] "<a href="ldap://$CustomerOU,$FQDN">LDAP://$CustomerOU,$FQDN</a>"
        $CreateOU = $CustomerOU.Create("OrganizationalUnit", "OU=$CustomerID")
        $CreateOU.SetInfo()
        If(!$CreateOU)
        {
            Write-Host "An Error Occurred."
        }
    }
    Else
    {
        Write-Host "Organizational Unit already exist on the Server" | Out-Null
        $Status = "1"
    }
}

This script creates an organizational unit under another one using some arguments.