AD Connection - Powershell

Hi there,

I have a script which runs a report on all accounts in AD and returns results on accounts which haven’t been logged in to in the last 30 days.

This works fine however, I would like to run this report against a different domain. Is there something I can enter at the beginning of my script which allows me to authenticate against another domain at all?

I’ve tried Set-Location using the domains distinguished name but it returns a message saying it does not exist.

Try using the -Server parameter and use the FQDN of a server in the other domain.

Well you could just google/“favourite search engine” it :slight_smile:

A believe this was the first link in the list that I got:

Connect to other domain

So basically you could use New-PSDrive to make the connection to the second domain.
Hope that helps.

Edit: not sure what happened to the link.

Use this:

$DC = Get-ADDomainController -Discover -DomainName 'foo.bar' -NextClosestSite | Select -ExpandProperty Hostname

$Users = Get-ADusers -Server $DC -filter '*'

Thanks for the posts guys.
I will give these a try and let you know how I get on.