Kelly Garcia
asked on
Accounts with UPN, Powershell
HI All,
I have a long list of users accouts, contacts, etc. I need to check which ones have UPN and which ones do not and then output them into an excel.
I have written this code, however it stops. I think i need to filter out the contacts. Please help!
Get-Content .\userid2.txt | % { Get-QADUser $_ | ? {$_.UserPrincipalName -notlike $null} } > noupn2.txt
Get-Content .\userid.txt | % { Get-QADUser $_ | ? {$_.UserPrincipalName -like $null} } > noupn.txt
I was then going to copy and paste the results to excel.
Regards,
Kay
I have a long list of users accouts, contacts, etc. I need to check which ones have UPN and which ones do not and then output them into an excel.
I have written this code, however it stops. I think i need to filter out the contacts. Please help!
Get-Content .\userid2.txt | % { Get-QADUser $_ | ? {$_.UserPrincipalName -notlike $null} } > noupn2.txt
Get-Content .\userid.txt | % { Get-QADUser $_ | ? {$_.UserPrincipalName -like $null} } > noupn.txt
I was then going to copy and paste the results to excel.
Regards,
Kay
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Kay,
I did overlook the fact that you did say you have contacts in your list as well. However my command will in fact work for a list of users.
I did overlook the fact that you did say you have contacts in your list as well. However my command will in fact work for a list of users.
Not with the missing pipe in between Get-Content and ForEach-Object it won't.
Why not just dump all users into a CSV and then just use Excel to filter as to whether or not they have a UPN?
Otherwise...
Has UPN
gc userid.txt | Get-ADUser | Select Name, Userprincipalname | export-csv c:\allusersupn.csv
Otherwise...
Has UPN
gc userid.txt | Get-ADUser -Filter {Userprincipalname -like "*"} | export-csv c:\hasupn.csv
Has no UPNgc userid.txt | Get-ADUser -Filter {Userprincipalname -notlike "*"} | export-csv c:\noupn.csv
I have something easier for you. Put all the users in one list and name it users.txt
1. Open powershell with (run as administrator)
2. Type import-module activedirectory
3. Copy and past this command
Get-content C:\pathtoyourfile\users.tx
Get-ADuser -filter * -property Userprincipalname | select samaccountname,userprincip
**edit the command to match your paths**
This will give you a complete list of users with their upn and users who have blank upns