Click here to Skip to main content
15,900,818 members
Home / Discussions / C#
   

C#

 
GeneralRe: Viewing the data enterd in the SQL Server Database for a specifed Time frame. Pin
OriginalGriff6-Feb-14 23:55
mveOriginalGriff6-Feb-14 23:55 
GeneralRe: Viewing the data enterd in the SQL Server Database for a specifed Time frame. Pin
Shameel7-Feb-14 0:07
professionalShameel7-Feb-14 0:07 
GeneralRe: Viewing the data enterd in the SQL Server Database for a specifed Time frame. Pin
Mohan Subramani7-Feb-14 2:32
Mohan Subramani7-Feb-14 2:32 
GeneralRe: Viewing the data enterd in the SQL Server Database for a specifed Time frame. Pin
OriginalGriff7-Feb-14 2:42
mveOriginalGriff7-Feb-14 2:42 
GeneralRe: Viewing the data enterd in the SQL Server Database for a specifed Time frame. Pin
Mohan Subramani7-Feb-14 2:58
Mohan Subramani7-Feb-14 2:58 
GeneralRe: Viewing the data enterd in the SQL Server Database for a specifed Time frame. Pin
OriginalGriff7-Feb-14 3:23
mveOriginalGriff7-Feb-14 3:23 
AnswerRe: Viewing the data enterd in the SQL Server Database for a specifed Time frame. Pin
KeyStrokes7-Feb-14 2:21
KeyStrokes7-Feb-14 2:21 
QuestionHow to run Import-PSSessions (powershell command) from .C# program Pin
Eviatar Gerzi6-Feb-14 7:51
Eviatar Gerzi6-Feb-14 7:51 
I am trying to write code in C# that get mailbox details from user via Power Shell command.

The power shell command script is:
C#
Import-PSSession -session (New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://myServer.myDomain.com/Powershell)
Get-Mailbox -Identity helpdesk


The script runs OK from PowerShell.

Now my goal is to run it using C#.

This is my function:
C#
private void button1_Click(object sender, EventArgs e)  
{
    m_RunSpace = RunspaceFactory.CreateRunspace();

    m_RunSpace.Open();

    Pipeline pipeLine = m_RunSpace.CreatePipeline();

    Command newSession = new Command("New-PSSession");
    newSession.Parameters.Add("-ConfigurationName", "Microsoft.Exchange");
    newSession.Parameters.Add("-ConnectionUri", "http://myServer.myDomain.com/Powershell");

    Command createSessionForExch = new Command("Import-PSSession");
    createSessionForExch.Parameters.Add("-Session", newSession);

    Command getMailbox = new Command("Get-Mailbox");
    getMailbox.Parameters.Add("-Identity", "helpdesk");

    pipeLine.Commands.Add(createSessionForExch);
    pipeLine.Commands.Add(getMailbox);

    Collection<PSObject> commandResults = pipeLine.Invoke();

    foreach (PSObject cmdlet in commandResults)
    {


    }
}



But I receive an error that the "Get-Mailbox" command is not recognize:
http://imageshack.com/a/img593/664/x52q.png

Probably because the Import-PSSessions wasn't invok correctly.

I need help how to run the command Import-PSSession correctly from C#
AnswerRe: How to run Import-PSSessions (powershell command) from .C# program Pin
Eviatar Gerzi11-Feb-14 8:44
Eviatar Gerzi11-Feb-14 8:44 
QuestionRegEx problem #2 [solved] Pin
Marco Bertschi6-Feb-14 2:32
protectorMarco Bertschi6-Feb-14 2:32 
AnswerRe: RegEx problem #2 Pin
OriginalGriff6-Feb-14 2:54
mveOriginalGriff6-Feb-14 2:54 
GeneralRe: RegEx problem #2 Pin
Marco Bertschi6-Feb-14 3:00
protectorMarco Bertschi6-Feb-14 3:00 
GeneralRe: RegEx problem #2 Pin
OriginalGriff6-Feb-14 3:11
mveOriginalGriff6-Feb-14 3:11 
GeneralRe: RegEx problem #2 Pin
Marco Bertschi6-Feb-14 3:13
protectorMarco Bertschi6-Feb-14 3:13 
GeneralRe: RegEx problem #2 Pin
Ravi Bhavnani6-Feb-14 6:54
professionalRavi Bhavnani6-Feb-14 6:54 
GeneralRe: RegEx problem #2 Pin
Marco Bertschi6-Feb-14 8:59
protectorMarco Bertschi6-Feb-14 8:59 
AnswerRe: RegEx problem #2 Pin
Kornfeld Eliyahu Peter6-Feb-14 3:19
professionalKornfeld Eliyahu Peter6-Feb-14 3:19 
GeneralRe: RegEx problem #2 Pin
Marco Bertschi6-Feb-14 3:28
protectorMarco Bertschi6-Feb-14 3:28 
AnswerMessage Closed Pin
6-Feb-14 3:26
professionalPeter Leow6-Feb-14 3:26 
GeneralRe: RegEx problem #2 Pin
Marco Bertschi6-Feb-14 3:28
protectorMarco Bertschi6-Feb-14 3:28 
AnswerRe: RegEx problem #2 [solved] Pin
Nicholas Marty6-Feb-14 4:01
professionalNicholas Marty6-Feb-14 4:01 
GeneralRe: RegEx problem #2 [solved] Pin
Marco Bertschi6-Feb-14 4:22
protectorMarco Bertschi6-Feb-14 4:22 
AnswerRe: RegEx problem #2 [solved] Pin
BillWoodruff6-Feb-14 4:16
professionalBillWoodruff6-Feb-14 4:16 
QuestionRequested registry access is not allowed. Pin
Jassim Rahma5-Feb-14 23:02
Jassim Rahma5-Feb-14 23:02 
AnswerRe: Requested registry access is not allowed. Pin
OriginalGriff5-Feb-14 23:11
mveOriginalGriff5-Feb-14 23:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.