Author Posts

April 27, 2017 at 8:46 am

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.

April 27, 2017 at 1:51 pm

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

April 27, 2017 at 2:11 pm

Well you could just google/"favourite search engine" it 🙂

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.

April 28, 2017 at 6:36 am

Use this:

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

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

May 4, 2017 at 2:48 pm

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