From: NZSchoolTech on
Good day,

If I open a Powershell remote session to Outlook Live and type
get-Recipient -recipientType mailboxuser, mailcontact
It returns a list of mailbox users and mail contacts as expected.

If I create a C# application to call remote powershell and pass it the same
command and parameters as above
Instead of returning a list of mailbox users and mail contacts, it returns
ONLY the list of MailUniversalDistributionGroup recipient types instead.

It looks like the only way in a C# application I can get the recipients I
want is to get all of them and iterate the collection and throw out the ones
that are not those two types that I want (as listed above).

--


From: Marco Shaw [MVP] on
Can you share some of your code?

Marco

"NZSchoolTech" <nzschooltech(a)education.nz> wrote in message
news:#nC8wRm6KHA.3184(a)TK2MSFTNGP05.phx.gbl...
> Good day,
>
> If I open a Powershell remote session to Outlook Live and type
> get-Recipient -recipientType mailboxuser, mailcontact
> It returns a list of mailbox users and mail contacts as expected.
>
> If I create a C# application to call remote powershell and pass it the
> same command and parameters as above
> Instead of returning a list of mailbox users and mail contacts, it returns
> ONLY the list of MailUniversalDistributionGroup recipient types instead.
>
> It looks like the only way in a C# application I can get the recipients I
> want is to get all of them and iterate the collection and throw out the
> ones that are not those two types that I want (as listed above).
>
> --
>
>
From: NZSchoolTech on
Pretty simple, it is a console app at the moment (for testing)

static void Main(string[] args)
{
string CredentialName = "something";
string passwd = "something";

SecureString password = new SecureString();

foreach (char c in passwd) {password.AppendChar(c);}

PSCredential credential = new PSCredential(CredentialName,
password);

Uri liveIdconnectionUri = new
Uri("https://pod51003psh.outlook.com/PowerShell-LiveID?PSVersion=2.0");

// Set the connection Info
WSManConnectionInfo connectionInfo = new
WSManConnectionInfo(liveIdconnectionUri,
"http://schemas.microsoft.com/powershell/Microsoft.Exchange",
credential);

connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;

// create a runspace on a remote path
// the returned instance must be of type RemoteRunspace

Runspace runspace =
System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);

PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();
command.AddCommand("Get-Recipient");
command.AddParameter("RecipientType", "usermailbox, mailcontact");
powershell.Commands = command;
try
{
// open the remote runspace
runspace.Open();
// associate the runspace with powershell
powershell.Runspace = runspace;
// invoke the powershell to obtain the results
Collection<PSObject> results = powershell.Invoke();

//spew out some data

foreach (PSObject obj in results)
{
Console.Write(obj.Members["DisplayName"].Value.ToString());
Console.Write(" ");
Console.Write(obj.Members["RecipientType"].Value.ToString());
Console.WriteLine();
}

Console.WriteLine();
Console.WriteLine("Press any key to continue");
Console.ReadKey();
}
finally
{
// dispose the runspace and enable garbage collection
runspace.Dispose();
runspace = null;
// Finally dispose the powershell and set all variables to null to
free
// up any resources.
powershell.Dispose();
powershell = null;

}


--


"Marco Shaw [MVP]" <marco.shaw(a)NO_SPAMgmail.com> wrote in message
news:#f$2Fnr6KHA.3656(a)TK2MSFTNGP06.phx.gbl...
> Can you share some of your code?
>
> Marco
>
> "NZSchoolTech" <nzschooltech(a)education.nz> wrote in message
> news:#nC8wRm6KHA.3184(a)TK2MSFTNGP05.phx.gbl...
>> Good day,
>>
>> If I open a Powershell remote session to Outlook Live and type
>> get-Recipient -recipientType mailboxuser, mailcontact
>> It returns a list of mailbox users and mail contacts as expected.
>>
>> If I create a C# application to call remote powershell and pass it the
>> same command and parameters as above
>> Instead of returning a list of mailbox users and mail contacts, it
>> returns ONLY the list of MailUniversalDistributionGroup recipient types
>> instead.
>>
>> It looks like the only way in a C# application I can get the recipients I
>> want is to get all of them and iterate the collection and throw out the
>> ones that are not those two types that I want (as listed above).
>>
>> --
>>
>>