Home |

Trigat

ADActive

10-11-2017

Language or Platform: Powershell

Code:

################################################################################################
# Search using displayname(FirstName and Lastname)  Then save results to .csv
# List if person is active or not in A.D.

Import-Module ActiveDirectory

$aResults = @()
$List = Get-Content "C:\ADActive\users.txt"
            
ForEach($Item in $List){
    $Item = $Item.Trim()
    $User = Get-ADUser -Filter{displayName -like $Item} -Properties SamAccountName, enabled, GivenName, Surname, telephoneNumber, mail

    $hItemDetails = New-Object -TypeName psobject -Property @{    
        FullName = $Item
        Active = $User.enabled
        UserName = $User.SamAccountName
        Email = $User.mail
        Tel = $User.telephoneNumber
    }

    #Add data to array
    $aResults += $hItemDetails
}

$aResults | Export-CSV "C:\ADActive\results.csv"

Back