I have been asked to go through and clean up the AD for the company which is a mess, a part of the clean-up is to populate the department field
with the user's parent OU name
OU = IT
User = Chris
Department = IT
I have created a PowerShell script that will do most of my clean-up for me, but I am having issues with the department, cos as I understand it the
parent OU contactor is not really a contractor.
There is the basic layout of my code so far
#$ous = Get-ADUser -Filter * -SearchBase "OU=xxx,DC=xxxx,DC,=xxx"
foreach($ou in $ous)
{
$ou.Title = "Student"
$ou.Title = "Student"
$ou.streetAddress = "Prince Philip Barracks"
# $ou.postOfficeBox = "PO Box 12345"
$ou.l = "Bordon"
$ou.st = "Hampshire"
$ou.postalCode = "GU35 0JE"
$ou.co = "United Kingdom"
Set-ADUser -Instance $ou
}
Want I would like to do is something like
$ou.department = ************ but I am not sure on how to go about this, I have found and read about some code
Example
Get-ADUser -Filter * -Properties distinguishedname,cn |
select @{n='ParentContainer';e={$_.distinguishedname -replace "CN=$($_.cn),",''
but I am not sure on how to import this into the body of my code.
Any ideas?