N
N
Nadudeigrec2021-02-11 11:14:56
PowerShell
Nadudeigrec, 2021-02-11 11:14:56

How to get the login and mail of the user from AD from the local machine knowing his full name?

There is a text file with a list of full names, local PC. It is necessary to get a list of full name, login, mail from AD and upload it to a file. Can this be done in python? (just started learning the basics).

I found such a script on the Internet. Unfortunately, the script has no comments. Will he be suitable for this? how to add a filter by full name from a file to it?

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = " LDAP://cn=Users,dc=test,dc=ru "
$objSearcher.Filter = "(&(objectCategory=person)(!userAccountControl: 1.2.840.113556.1.4.803:=2))"
$users = $objSearcher.FindAll()
# Number of accounts
$users.Count
$users | ForEach-Object {
$user = $_.Properties
New-Object PsObject -Property @{
Title = [string]$user.description
Department = [string]$user.department
Login = [string]$user.userprincipalname
Phone = [string]$user. telephonenumber
room = [string]$user.physicaldeliveryofficename last
name = [string]$user.cn
}
} | Export-Csv -NoClobber -Encoding utf8 -Path "c:\ist_users.csv"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nadudeigrec, 2021-02-12
@Nadudeigrec

Here is the script I am running. In line LDAP covered up the information.
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = " LDAP://cn=Users,OU= ,OU=Moscow,OU=Regions,DC=,DC=,DC=com"
$objSearcher.Filter = "(&(objectCategory=person)(!userAccountControl:1.2.840.113556.1.4.803:=2))"
$usersList = Import-Csv D:\test\FIOlist.csv -Header DisplayName
ForEach ($userName in $userslist ) {
Get-ADUser -Filter { displayName -like $userName } | Select samAccountName, email, displayname > D:\test\export1.csv}
D:\test> .\script.ps1
Gives:
The name 'Get-ADUser' is not recognized as the name of a cmdlet, function, script file, or executable program. Check the spelling of the name and the presence and correctness of the path, then try again.
D:\test\script.ps1:9 char:11
+ Get-ADUser <<<< -Filter { displayName -like $userName } | Select samAccountName, email, displayname > D:\test\export1.csv}
+ CategoryInfo : ObjectNotFound: (Get-ADUser:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
What's the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question