Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Use AD cmdlets against another domain in a different forest

$
0
0

My user account and machine where migrated to a new domain in a different forest last night. My account in the old domani is still active, as there is still stuff I need to do until we get rid of it.

I am trying to run some AD cmdlets, to take care of some objects in the old domain, but it is trying to run against the objects in the new domain, which I believe is because the machine I am running from is on the new domain. How can I force it to run against the old domain? My script is as follows:

Import-Module ActiveDirectory
cls

$ouName = "Some OU"
$moveOU = "OU=No Migrate,OU=$ouName,OU=Parent,DC=old,DC=domain,DC=com"

Get-ADComputer -Server server.old.domain.com -Filter * -SearchBase "OU=$ouName,OU=Parent,DC=old,DC=domain,DC=com" -Properties LastLogonDate | ForEach-Object {`
	If ($_.LastLogonDate -le (Get-Date).AddDays(-30))
	{
		If ($_.Enabled -eq $true)
		{
			Set-ADComputer -Identity $_.sAMAccountName -Enabled $false
		}
		
		Move-ADObject -Identity $_.DistinguishedName -TargetPath $moveOU
	}
}

So basically it goes through and finds any machine that hasn't logged in within 30 days, disables it then moves it to the specified OU. I added the -server parameter, to force it to use a server within that domain, but yet still fails saying it can not find an object with the specified name, within the new domain.

Is it possible to use the general AD cmdlets, acrss domains in different forests, or do I need to run them from a machine that is on the old domain?


If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>