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.
Locked
User avatar
localpct
Posts: 271
Joined: Wed Sep 09, 2015 12:53 pm

Get-Aduser and DGV

Post by localpct » Thu Jul 19, 2018 11:28 pm

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

Code: Select all

$properties = @(
'BadLogonCount',
'badPasswordTime',
'badPwdCount',
'CanonicalName',
'City'
)
$users = get-aduser -Identity username -Properties $properties | Select-Object $properties
Update-DataGridView -DataGridView $datagridview1 -Item $users

User avatar
jvierra
Posts: 13275
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Get-Aduser and DGV

Post by jvierra » Thu Jul 19, 2018 11:37 pm

Works fine for me.

One user - one row.

User avatar
localpct
Posts: 271
Joined: Wed Sep 09, 2015 12:53 pm

Re: Get-Aduser and DGV

Post by localpct » Thu Jul 19, 2018 11:39 pm

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 683 times

User avatar
jvierra
Posts: 13275
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Get-Aduser and DGV

Post by jvierra » Thu Jul 19, 2018 11:45 pm

You are only using Get-AdUser. The code does not get group membership.

User avatar
localpct
Posts: 271
Joined: Wed Sep 09, 2015 12:53 pm

Re: Get-Aduser and DGV

Post by localpct » Thu Jul 19, 2018 11:46 pm

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

User avatar
jvierra
Posts: 13275
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Get-Aduser and DGV

Post by jvierra » Thu Jul 19, 2018 11:57 pm

I cannot know what you are doing if you don't post the correct code.

User avatar
localpct
Posts: 271
Joined: Wed Sep 09, 2015 12:53 pm

Re: Get-Aduser and DGV

Post by localpct » Fri Jul 20, 2018 12:10 am

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 627 times

User avatar
jvierra
Posts: 13275
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Get-Aduser and DGV

Post by jvierra » Fri Jul 20, 2018 12:19 am

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: 271
Joined: Wed Sep 09, 2015 12:53 pm

Re: Get-Aduser and DGV

Post by localpct » Fri Jul 20, 2018 12:21 am

I’ll post my code tomorrow

User avatar
localpct
Posts: 271
Joined: Wed Sep 09, 2015 12:53 pm

Re: Get-Aduser and DGV

Post by localpct » Fri Jul 20, 2018 10:34 am

Can we delete this thread so I can start a fresh one?

Locked