looking for a powershell script that provides specific ad user account attribute

for example i run the script and i am able to type user account and see if the value is there - want to provide this to helpdesk make it easy on them rather then look for it in attributes and scrolling.
LVL 2
Jorge OcampoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
Can you provide more detail? What attributes are you looking for?

Will.
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The basic elements of what I think you are asking for:
$usr = read-host 'user name? '
Get-ADUser $usr -Properties TheNameOfAttributeHere

Open in new window

0
Muhammad BurhanManager I.T.Commented:
display selected 'attr' from all properties.

$usr = read-host 'user name?'
Get-ADUser $usr -Properties * | select UserPrincipalName

Open in new window


this will generate csv with selected attributes.

$usr = read-host 'user name?'
Get-ADUser $usr -Properties * | select SamAccountName,UserPrincipalName,PrimaryGroup,CanonicalName | Export-Csv  "c:\Users.csv"

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Jorge OcampoAuthor Commented:
Where do i write the users name? do i have to build a .ps1 script or can i run inside powershell?
0
Will SzymkowskiSenior Solution ArchitectCommented:
The Read-Host cmdlet will prompt you to enter a name. Once you enter the name it will use that name in the script. Yes save the script filename.ps1

Will.
0
Jorge OcampoAuthor Commented:
everytime it prompts me to enter user it closes after that unless i open windows powershell ISE
0
Will SzymkowskiSenior Solution ArchitectCommented:
Run the .ps1 file from powershell directly. Either type Pause on line 3 this will keep the window open.

Will.
0
Jorge OcampoAuthor Commented:
can i make the username? UPN instead?
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
How about if you just try that?
0
Jorge OcampoAuthor Commented:
Something like below but seems to not work

$upn = read-host 'Please Enter User Email'
Get-ADUser $upn -Properties * | select ADAttribute
Pause
0
Will SzymkowskiSenior Solution ArchitectCommented:
Just and fyi UPN is not email just so you know.

Will.
0
Jorge OcampoAuthor Commented:
anyway to prompt for UPN and display an attribute of my choice?
0
Will SzymkowskiSenior Solution ArchitectCommented:
Try that below

Import-module activedirectory
$Attribute = read-host "Type your Attribute Here!"
$upn = read-host "Type UPN i.e user@domain.local"
Get-ADUser -identity $upn -Properties * | select  $Attribute
Pause 

Open in new window


Because get-aduser will take multiple different values with the Identity Parameter you cannot force it to take just the UPN.

Will.
0
Jorge OcampoAuthor Commented:
Get the following error "Get-ADUser : Cannot find an object with identity:  username@domain.com under: DC=?,DC=?,DC=Global

even though it is the correct location and i checked the userprinciplename and its there

any suggestions?
0
Will SzymkowskiSenior Solution ArchitectCommented:
Sorry...looking at the Identity parameter it will only accept the following....
- samaccountname
- distinguishedName
- GUID

It will not accept UPN so modfiy it to look like below...
Import-module activedirectory
$Attribute = read-host "Type your Attribute Here!"
$sAMAccountName = read-host "Type sAMAccountName i.e user1"
Get-ADUser -identity $sAMAccountName -Properties * | select  $Attribute
Pause 

Open in new window


Will.
0
Jorge OcampoAuthor Commented:
:( this is for level1 unless the samaccount is provided to them they are going to have a hard time. they only know the users email address
0
Will SzymkowskiSenior Solution ArchitectCommented:
I guess you could also use the -filter parameter and filter on UPN or email address using the -eq or -match switch.

Will.
0
Jorge OcampoAuthor Commented:
trying to understand how that would look?
0
Will SzymkowskiSenior Solution ArchitectCommented:
Get-ADUser -filter {UserPricipalName -match $upn}

Or

Get-ADUser -filter * -Properties * | ? {$_.UserPrincipalName -eq $upn} | select $Attribute

Something like that.

Will.
0
Jorge OcampoAuthor Commented:
something like this?

Import-module activedirectory
$Attribute = read-host "Type your Attribute Here!"
$upn = read-host "Type UPN i.e user@domain.local"
Get-ADUser -filter * -Properties * | ? {$_.UserPrincipalName -eq $upn} | select $Attribute
Pause
0
Jorge OcampoAuthor Commented:
yup that works but its SUPER SLOW!
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The filter condition should be faster. You should also not use -Properties *, but only retrieve necessary properties (attributes)  with Get-ADUser.
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
That is:
Import-module activedirectory
$Attribute = read-host "Type your Attribute Here!"
$upn = read-host "Type UPN i.e user@domain.local"
Get-ADUser -filter "UserPrincipalName -eq '$upn' " -Properties $Attribute | select UserPrincipalName, Name, $Attribute
Pause

Open in new window

or
Import-module activedirectory
$Attribute = read-host "Type your Attribute Here!"
$upn = read-host "Type UPN i.e user@domain.local"
Get-ADUser -filter {UserPrincipalName -eq $upn} -Properties $Attribute | select UserPrincipalName, Name, $Attribute
Pause

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.