?
Solved

Issue moving computers from one OU to another

Posted on 2011-05-04
4
Medium Priority
?
864 Views
Last Modified: 2012-06-21

I need to move all the computer objects from a particular OU in Active Directory to another OU. I have a code that does the job

$ou = [ADSI]"LDAP://OU=SourceOU,OU=Test CC,DC=test,DC=com"

foreach ($item in $ou.psbase.Children){
	
if ($item.ObjectCategory -like '*computer*') { 
	#Write-Host $item.name


	switch($os)
	{
		"Windows XP"
		{
			$os= "Test XP"
		}

		"Windows 7"
		{
			$os= "Test W7"
		}
		"Windows 2000"
		{
			$os= "Test W2K"
		}
		"Windows Vista"
		{
			$os= "Test Vista"
		}
					
	}

	$new_ou="OU=" + $os + ",OU=Test CC,DC=test,DC=com"
				
	
	Move-QADObject $item.name.tostring() -To $new_ou

				
}

Open in new window


The problem is that some computer objects have a corresponding user object in AD (autologin) and when I call Move-QADObject procedure it picks up the user objects and I get "Access denied" error. Can somebody help?
0
Comment
Question by:YZlat
  • 2
  • 2
4 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 35691847
Give Move-QADObject a unique ID instead:
Move-QADObject $item.Get("distinguishedName") -To $new_ou

Open in new window

You know you could do this with Get-QADComputer instead, right? Doesn't make a lot of difference, but would be more consistent.

Cheers,

Chris
0
 
LVL 35

Author Comment

by:YZlat
ID: 35691873
How do I do this with Get-QADComputer?
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 35691946
Pretty much the same way really, just makes it a little bit neater (perhaps).

Chris
Get-QADComputer -SearchRoot "OU=SourceOU,OU=Test CC,DC=test,DC=com" -SearchScope OneLevel | ForEach-Object {
  Switch ($_.OperatingSystem) {
    "Windows XP"    { $os = "Test XP" }
    "Windows 7"     { $os= "Test W7" }
    "Windows 2000"  { $os= "Test W2K" }
    "Windows Vista" { $os= "Test Vista" }
  }

  $_ | Move-QADObject -To "OU=$os,OU=Test CC,DC=test,DC=com"
}

Open in new window

0
 
LVL 35

Author Closing Comment

by:YZlat
ID: 35691948
Worked like a charm! Thank yoU!
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Loops Section Overview

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question