Connecting to Outlook Live via Powershell script from C# app

N

NZSchoolTech

Good day,

I am just starting out with Visual C# Express, although I have many years of
experience in programming other languages including C.

I have found some examples of how to execute Powershell scripts from a C#
application. Such as:
http://www.devx.com/tips/Tip/42716

What I want to do is a little more complex because there are several
commands that have to be executed and they include storing a result and
passing that result to another command.
Specifically to connect to Outlook Live via Powershell, the following
sequence is required:

$LiveCred = Get-Credential

$Session = New-PSSession -ConfigurationName
Microsoft.Exchange -ConnectionUri
https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication
Basic -AllowRedirection

Import-PSSession $Session

As can be seen the results of two of the commands are stored in variables
(objects) to be passed to other commands.

We don't want to create a new credential and session for every command since
we don't want the user to need to be re entering their credentials for each
command, and we would have to close each session before creating another one
with unnecessary time delay/overhead etc.

I want to do this so I can make a GUI application to edit some parameters of
each Mailbox object that aren't addressed by the provided GUI (Outlook Live
website) so it needs Powershell to do the back end stuff via scripting.

TIA

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top