Get-Aduser and DGV

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Get-Aduser and DGV

Post by localpct »

I'm trying to pull certain properties of a single user into a DGV, for some reason it's not adding the rows as I see from my searching it should be doing
  1. $properties = @(
  2.         'BadLogonCount',
  3.         'badPasswordTime',
  4.         'badPwdCount',
  5.         'CanonicalName',
  6.         'City'
  7.     )
  8.     $users = get-aduser -Identity username -Properties $properties | Select-Object $properties
  9.     Update-DataGridView -DataGridView $datagridview1 -Item $users
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-Aduser and DGV

Post by jvierra »

Works fine for me.

One user - one row.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Get-Aduser and DGV

Post by localpct »

Sorry, I completely posted the wrong question.

What I need is groupmembership. It's only returning the length

$users = ([ADSISEARCHER]"samaccountname=$($env:USERNAME)").Findone().Properties.memberof -replace '^CN=([^,]+).+$', '$1'
Update-DataGridView -DataGridView $datagridview1 -Item $users
2018-07-20_2-42-49.png
2018-07-20_2-42-49.png (3.21 KiB) Viewed 4521 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-Aduser and DGV

Post by jvierra »

You are only using Get-AdUser. The code does not get group membership.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Get-Aduser and DGV

Post by localpct »

Yes sorry. Please excuse the first post. It's completely wrong

I want to return the groupmembership in a DGV. As you can see from my above post it's only returning the length of the object.

It returns just fine in the ISE
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-Aduser and DGV

Post by jvierra »

I cannot know what you are doing if you don't post the correct code.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Get-Aduser and DGV

Post by localpct »

So I want to return the group membership using ADSI into a DGV of the current logged on user. Again, ignore what I originally asked for, that was an error on my behalf.

As you can see it's returning much more than the groupname

This is what I'm getting and the code I'm using
Results.png
Results.png (58.13 KiB) Viewed 4465 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-Aduser and DGV

Post by jvierra »

To get group membership use

Get-ADPrincipalGroupMembership userid

Please do not post pictures of code. They are mostly unreadable on the web and cannot be copied.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Get-Aduser and DGV

Post by localpct »

I’ll post my code tomorrow
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Get-Aduser and DGV

Post by localpct »

Can we delete this thread so I can start a fresh one?
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked