AD Connection - Powershell

This topic contains 4 replies, has 4 voices, and was last updated by  Andy 1 year ago.

  • Author
  • #69652


    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.

  • #69684

    Michael Delaney

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

  • #69690

    Fredrik Kacsmarck

    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.

  • #69733

    Roy Atkins

    Use this:

    $DC = Get-ADDomainController -Discover -DomainName '' -NextClosestSite | Select -ExpandProperty Hostname
    $Users = Get-ADusers -Server $DC -filter '*'
  • #70062


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

You must be logged in to reply to this topic.