Multiple select statements

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 6 years and 4 weeks 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
Shelltastic
Posts: 65
Last visit: Mon Feb 19, 2024 11:31 am

Multiple select statements

Post by Shelltastic »

Trying to find a way to return the friendly name of a manager of a distribution list. The following code is what is running now;

$dlmanagers = Get-DistributionGroup $dl | select -ExpandProperty Managedby

This returns the distinguished name of the manager(s);

domain.com/OU/OU/user

I'm looking to pull back the Name attribute, the following code works from a powershell console;

Get-DistributionGroup GroupName | select -expandproperty managedby | select -expandproperty name

That gives me the attribute that I want, however this command doesn't work when I run it from my application, it just comes back blank.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multiple select statements

Post by jvierra »

Get-DistributionGroup returns a group. "select -ExpandProperty Managedby" returns a string. YOu cannot get the "Name" of the manager form a string. The second example will not work anywhere.

Use this:

$managerDN = (Get-DistributionGroup GroupName).managedby
$managerName = (Get-A0dObject $managerDN).Name
User avatar
Shelltastic
Posts: 65
Last visit: Mon Feb 19, 2024 11:31 am

Re: Multiple select statements

Post by Shelltastic »

The second example does work from an Exchange shell, here a link to a screen shot of it working...

https://1drv.ms/u/s!AgBAbImA7NSlswTn_I7BNCtc3MXT

You'll see the first cmdlet returning the full result of the managedby, then the second example using multiple select statements that returns the attribute that I would like to output.

Tried using your suggestion, thank you by the way, but when I run the code I get the following error..

https://1drv.ms/u/s!AgBAbImA7NSlswZggXd70cqSMWNs
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multiple select statements

Post by jvierra »

$managerName = Split-Path ((Get-DistributionGroup GroupName).managedby) -Leaf
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multiple select statements

Post by jvierra »

This works for me:
Get-DistributionGroup AllUsers |select -expand managedby

or this

(Get-DistributionGroup AllUsers).managedBy
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multiple select statements

Post by jvierra »

The attached form works for me.
Attachments
TestForm2.psf
(27.81 KiB) Downloaded 125 times
User avatar
Shelltastic
Posts: 65
Last visit: Mon Feb 19, 2024 11:31 am

Re: Multiple select statements

Post by Shelltastic »

"Get-DistributionGroup AllUsers |select -expand managedby" works, but I am only trying to pull back the managers display name, this gives me all attributes.

I also tried "$managerName = Split-Path ((Get-DistributionGroup GroupName).managedby) -Leaf", gave me the following error.

https://1drv.ms/u/s!AABAbImA7NSlsxw
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multiple select statements

Post by jvierra »

The results give you the name of each manager. If you want the display name then you will have to get the mangers user account.

Get-User managerid | select DisplayName
This topic is 6 years and 4 weeks 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