Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7090601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:04:30+00:00 2026-05-28T08:04:30+00:00

I have 2 powershell scripts that I execute from c# which I’m using to

  • 0

I have 2 powershell scripts that I execute from c# which I’m using to first list message using an IMAP cmdlet and the 2nd script performs a view on a specific message. Both execute successfully from powershell, the 2nd one I am trying to retrieve an attachment and I see a bunch of data output to the console like so…

   Sent from my iPhone
   ------=_NextPart_000_0027_01CCDAA7.399EBE00
   Content-Type: image/jpeg; name="photo.JPG"
   Content-Transfer-Encoding: base64
   Content-Disposition: attachment; filename="photo.JPG"

   /9j/4QH6RXhpZgAATU0AKgAAAAgACgEPAAIAAAAGAAAAhgEQAAIAAAAHAAAAjAESAAMAAAABAAYA
   AAEaAAUAAAABAAAAlAEbAAUAAAABAAAAnAEoAAMAAAABAAIAAAEyAAIAAAAUAAAApAITAAMAAAAB
   AAEAAIdpAAQAAAABAAAAuIglAAQAAAABAAABZgAAAABBcHBsZQBpUGhvbmUAAAAAAEgAAAABAAAA
   SAAAAAEyMDA5OjA5OjIwIDE1OjEwOjU1AAAKgp0ABQAAAAEAAAE2kAAABwAAAAQwMjIxkAMAAgAA
   ABQAAAE+kAQAAgAAABQAAAFSkQEABwAAAAQBAgMAoAAABwAAAAQwMTAwoAEAAwAAAAEAAQAAoAIA
   BAAAAAEAAAZAoAMABAAAAAEAAASwpAYAAwAAAAEAAAAAAAAAAAAAAA4AAAAFMjAwOTowOToyMCAx

so it appears everything is fine so far – except there is I believe a difference in the function result as possible a stream/pipe from powershell?

The first one returns a collection of PSObjects which is called like so

            PowerShell ps = PowerShell.Create();
            ps.Runspace = runspace;
            ps.AddScript(script);
            ps.Invoke();

            foreach (PSObject result in ps.Invoke())
            {
                dynamic val = result.BaseObject;
            }

The 2nd script executes without error using Invoke() however trying to retrieve data via for each or

dynamic xx = ps2.Invoke();

xx is empty;

I thought maybe I need to use BeginInvoke and call asynchronously so I tried

    static dynamic GotMail(dynamic o)
    {
        return o;
    }

    delegate dynamic SomeDelegate(dynamic o);

    and attempted to use like so..

          SomeDelegate sd = GotMail;
          IAsyncResult ar = ps2.BeginInvoke();


          dynamic val2 = sd.EndInvoke(ar);

and I recieve “The async result object is null or of an unexpected type.” I’m not even passing parameters into the powershell scripts..everything is hardcoded – the script I run from powershell successfully is exactly what I execute from .NET

Any suggestions for this much appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:04:30+00:00Added an answer on May 28, 2026 at 8:04 am

    You’re invoking the script twice by calling Invoke() twice. Remove the first call to invoke e.g.:

    PowerShell ps = PowerShell.Create();
    ps.Runspace = runspace;
    ps.AddScript(script);
    //ps.Invoke();
    foreach (PSObject result in ps.Invoke()) {
        dynamic val = result.BaseObject;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an engine that executes powershell scripts, and when they execute, need to
I have several Powershell scripts that I want to execute on 4 remote machines.
I have an powershell script which is executing sql scripts from a given folder.
I have a Powershell script that copies files from one location to another. Once
I want to execute a powershell using the .net Powershell SDK. I have this
I'm pretty new to Powershell. I have 2 different scripts I'm running that I
I have a master script that is attempting to execute additional scripts against a
I have some PowerShell scripts that accept many long parameters, like, myScript.ps1 -completePathToFile C:\...\...\...\file.txt
We have a powershell build script that calls out to other scripts that is
I have a powershell script which imports data from a csv file, and then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.