AD Connection - Powershell

This topic contains 4 replies, has 4 voices, and was last updated by  Andy 5 months, 2 weeks ago.

  • Author
    Posts
  • #69652

    Andy
    Participant

    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
    Participant

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

  • #69690

    Fredrik Kacsmarck
    Participant

    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
    Participant

    Use this:

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

    Andy
    Participant

    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.