So my task is to move computer accounts in AD from their current Production-OU to the correspondent Pilot-OU. I received a text file that has all the computer account names in it but nothing else
computer1
computer2
computer3
...
Unfortunately I am pretty new in the company so I don't really know the OUs from experience and there is no database. I am also new to PowerShell and my PowerShell expert colleague is on vacation. So I am trying to put together a script something like this
$computers = Get-Content ".\computers.txt"
$computers | ForEach-Object {
IF object1's OU = Production1 {
Move-ADObject -TargetPath "OU=Pilot1"
ELSE {
IF object1's OU = Production2 {
Move-ADObject -TargetPath "OU=Pilot2"
ELSE {
Move-ADObject -TargetPath "OU=Pilot3"
}
}
}
}
}
I tried to figure out what cmdlet I could use to get the current OU and tried piping to Get-Member
but I am unable to figure out which filters or parameters to use and how.
CodePudding user response:
This will give you the current OU
((Get-ADComputer "Computername").DistinguishedName).Split(",")[1]