troubleshooting Question

Move computers from unassigned OU

Avatar of Kelly Garcia
Kelly GarciaFlag for United Kingdom of Great Britain and Northern Ireland asked on
Powershell
2 Comments1 Solution134 ViewsLast Modified:
Hi Guys,

I have written the script below and I only want to move machines upon meeting one of the conditions of the switch command, however the below moves every machine. please help!

$UnassignedComputers = Get-QADComputer -SearchRoot "CN=Computers,DC=X,DC=COM"
foreach ($UnassignedComputer in $UnassignedComputers){
$Prefix = $UnassignedComputer.NAME
$Adcomputer = Get-QADComputer -Name $Prefix
$Adcomputername = $Adcomputer | select -ExpandProperty name
switch -Wildcard ($Adcomputername) {
            "lp-lon*" {$ou="OU=London Laptops,OU=London Computers,OU=London,OU=Organisation,DC=X,DC=COM"}
            "pc-lon*" {$ou="OU=London PC,OU=London Computers,OU=London,OU=Organisation,DC=X,DC=COM"}
            "lp-rom*" {$ou="OU=Laptops,OU=Romania Computers,OU=Romania,OU=Organisation,DC=X,DC=COM"}
            "lp-sing*" {$ou="OU=Singapore Laptops,OU=Singapore,OU=Organisation,DC=X,DC=COM"}
	        }
	     if ($ou -ne $null) {Move-QADObject -Identity $AdComputer.DN -NewParentContainer $ou}

}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros