简体   繁体   中英

Get-ADUser for 2 columns from a CSV

I am having issues figuring out the best way to get AD user and | Select-Object SamAccountName for a data set where the first names and last names are in 2 separate columns on a csv.

What i have so far (im just starting this script)

$Results = @()

$Physician = Import-Csv -Path "$env:UserProfile\Desktop\Physicians.csv"


foreach($User in $Physician)

{

    $Uno = $User.FirstName

    $Dos = $User.LastName

    $Users = Get-ADUser -Filter 

}

I cant seem to find the best way to take my 2 name identifiers and use a filter to compare them both to AD and grab the SamAccountName

You could keep it simple and just add them together in a string:

$Physician = Import-Csv -Path "$env:UserProfile\Desktop\Physicians.csv"
$Results = $Physician | ForEach-Object {
    $Uno = $_.FirstName
    $Dos = $_.LastName
    $FullName = "$Uno $Dos"

    Get-ADUser -Filter {Name -eq $FullName} | Select Name , SamAccountName

}

$Results

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM