Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

get samaccountname

$
0
0

I have Googled this and I've gotten many scripts, so far none of them work and I know I had this working before.  I need to read a CSV file which has 3 columns LAST NAME, FIRST NAME, EMAIL ADDRESS.  I need to get the SamAccountName for each user.  I've tried a few things but they don't work or they return no data.  I've tried things like this:

 

foreach ($userin$users){
$SplitName=-split$user
Get-ADUser-Filter {(GivenName -eq$SplitName[0]) -and (Surname -eq$splitName[1])} |Select-Object name, samaccountname
}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Get-ADUser-Filter"Name -eq '$user'" | Select-Object name, samaccountname

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

$sam=get-content"C:\temp\cam\users.txt" | ForEach { Get-ADUser-Filter"name -eq '$_'" | Select SamAccountName }
$sam

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

$users = Import-Csv "c:\temp\users.csv"  

foreach ($user in $users) {

$sam = Get-ADUser -ldapfilter * -Property * | Select-Object -Property SamAccountName 

$sam}

 

 

How do you get the samaccountname?  

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles