Difficulty with Powershell in C#

rated by 0 users
This post has 0 Replies | 1 Follower

Not Ranked
Posts 1
speeters@prodware.be Posted: 03-12-2012 2:48 PM

Hi,

I'm trying to check whether mailcontact a is member of distributionlist b.

I've been wrestling with this for some hours now and can't find a solution.

 

so the command that should be passed is :

Get-DistributionGroupMember -Identity "b" | ft -autosize ExternalEmailAddress

I need to pipe it to get the email addresses of the members. Otherwise it only returns the name and type. 

 

Try 1 ( String.Format )

string.Format("Get-DistributionGroupMember -Identity \"{0}\" | ft -autosize ExternalEmailAddress",distributionListAlias)

When I pass this string through powershell he says that Get-DistributionGroupMember is not a cmdlet .....

Passing only "Get-MailContact" does work, do I try to do string.Format(" Get-MailContact  -Identity \"{0}\"",distributionListAlias), I get the same error but on Get-MailContact.

So it's not a problem with the Exchange PSplugin, I load that in my RunSpaceConfiguration

 

Try 2 ( Pipeline attempt 1)

 

Command pwCommand = new Command("Get-DistributionGroupMember");

 CommandParameter thisParam = new CommandParameter("Identity", distributionListAlias);

 pwCommand.Parameters.Add(thisParam);

string commandScript = "ft -autosize ExternalEmailAddress";

 

and I add those two to my pipe, same error on ft, cmdlet UnknownCommandExeption.

 

Try 3 (Pipeline attempt 2)

Tried to figure out how I could simulate the "ft -autosize ExternalEmailAddress" via a command object, but no luck.

 

 

Can anybody help me please?

 

Regards,

Sven Peeters

Belgium

 

 

Page 1 of 1 (1 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.