Greetings,
I'm working for a medium to large enterprise that has never taken time to organize their computer objects based on site OU. Currently all of our machines are grouped under one OU. However each site has an independent DCHP scope, so the addresses are 192.168.1.x, 192.168.2.x, ect. So what I would like to do is use powershell to filter by subnet basically and move the objects to the corresponding OU. I am not new to powershell, but am by no means an expert. I was reviewing a post from a Eric Wright, but it's from 2011.
https://devblogs.microsoft.com/scripting/use-powershell-to-move-computers-based-on-ip-addresses-part-1/
There is a link to the full script, but it has long since broken.
In any case, this is the script I'm currently working with.
$ADComps= Get-ADComputer -Filter * -SearchBase "OU=Computers,DC=test,dc=com" -Properties ipv4address | Select-Object -Property Name, ipv4address |sort -Property name | Out-GridView -PassThru –title “Select Computers to Move”| Select -ExpandProperty Name
$ADOUs= Get-ADOrganizationalUnit -Filter * | Select-Object -Property DistinguishedName | Out-GridView -PassThru –title “Select Target OU”| Select-Object -ExpandProperty DistinguishedName
Foreach($ou in $ADOUs){
Foreach($comp in $ADComps){
get-adcomputer $comp |Move-ADObject -TargetPath "$ou" -Verbose }
}
And this works for what it's doing. But I'm trying to filter it down so that I can only aggregate the machines within the specific subnets so that I can move them with a bit more automation rather than selecting from the list and doing it that way. Any help is appreciated! Thanks everyone in advance!
Dave M-