'Checking ExtensionAttributes
I had a list of 50 users with the Active Directory extensionAttribute12
sent to me, I was told that extensionAttribute13
was mixed up. So far, as I go through and check in AD, I don't see this to be so.
I would like to use PowerShell to check the list he gave me and export to my own list without going one by one.
I have this and when I runs it seems to export all users, but in my list, I only have 1 user. Later, I would like to run on the list of 50. I don't understand why I get all of the users.
Import-Module ActiveDirectory
$UserList=Import-Csv C:\Users\RHyman\Documents\ExListTest.csv
FOREACH ($Person in $UserList)
{
Import-Csv C:\Users\rhyman\Documents\ExListTest.csv | ForEach {
Get-ADUser -Filter * -Properties UserPrincipalName, extensionAttribute12, emailAddress, SAMAccountName | `
Select UserPrincipalName, extensionAttribute12, extensionAttribute13 | `
Export-CSV c:\allinfo.csv -NoTypeInformation
}
}
I've done some editing, this is what I have now:
Import-Module ActiveDirectory
$UserList=Import-Csv C:\Users\RHyman\Documents\ExListTest.csv
FOREACH ($Person in $UserList)
{
Get-ADUser -Identity "$UserList" -Properties UserPrincipalName, extensionAttribute12, emailAddress, SAMAccountName |
Select UserPrincipalName, extensionAttribute12, extensionAttribute13 |
Export-CSV C:\Users\RHyman\Documents\allinfo.csv -NoTypeInformation
}
What I'm most concerned with is that the Get-Aduser
has error:
Cannot find an object with identity: '@{[email protected]
It sees the name on the list but I may have to go to the csv file and change the way the list displays the names.
Revised script: Only thing now exported csv is empty
Import-Module ActiveDirectory $UserList=Import-Csv C:\Users\RHyman\Documents\ExListTest.csv FOREACH ($Person in $UserList) {
Get-ADUser -Filter {(mail -eq "$UserList")} -Properties
UserPrincipalName, extensionAttribute12, emailAddress, SAMAccountName |
Select UserPrincipalName, extensionAttribute12, extensionAttribute13 |
Export-CSV C:\Users\RHyman\Documents\allinfo.csv -NoTypeInformation
}
Finally got what I was looking for and it does what I wanted This is what I needed and used Get-Content Get-ADUser -Filter {mail -like $_}
Thanks for all the help!
Solution 1:[1]
You are passing entire csv [Get-ADUser -Identity "$UserList"] into Identity use below instead.
$UserList=Import-Csv C:\Users\RHyman\Documents\ExListTest.csv FOREACH ($Person in $UserList) {
Get-ADUser -Identity $UserList.UserPrincipalName
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | NK149 |