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 7665037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:27:30+00:00 2026-05-31T14:27:30+00:00

As described in my question Create ISO image using PowerShell: how to save IStream

  • 0

As described in my question Create ISO image using PowerShell: how to save IStream to file?, in PowerShell I create an IStream object as follows:

$is = (New-Object -ComObject IMAPI2FS.MsftFileSystemImage).CreateResultImage().ImageStream

This object is of (PowerShell) type System.__ComObject. And somehow PowerShell knows that it is an IStream:

PS C:\> $is -is [System.Runtime.InteropServices.ComTypes.IConnectionPoint]
False
PS C:\> $is -is [System.Runtime.InteropServices.ComTypes.IStream]
True

However, a cast to this type fails:

PS C:\> [System.Runtime.InteropServices.ComTypes.IStream] $is
Cannot convert the "System.__ComObject" value of type "System.__ComObject" to type "System.Runtime.InteropServices.ComT
ypes.IStream".
At line:1 char:54
+ [System.Runtime.InteropServices.ComTypes.IStream] $is <<<<
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

How do I make this conversion work, without using C# code?

Update: Apparently this conversion cannot be made to work, as x0n’s answer says.

Now, my goal is to pass this IStream COM object to some C# code (part of the same PowerShell script using Add-Type), where it would become a .NET object of type System.Runtime.InteropServices.ComTypes.IStream. Is that possible? If not, what alternatives do I have?

  • 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-31T14:27:32+00:00Added an answer on May 31, 2026 at 2:27 pm

    You can try to pass $is in a (unsafe) c# method like an objecttype and try to handle it with a VARdeclared as System.Runtime.InteropServices.ComTypes.IStream

    public unsafe static class MyClass
    {
        public static void MyMethod(object Stream) 
        {
           var i = Stream as System.Runtime.InteropServices.ComTypes.IStream; 
    
        //do something with i like i.read(...) and i.write(...)
        }
    }
    

    In powershell after the add-type:

    [MyClass]::MyMethod($is)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the method described in this question to load intial users for
I am using the code as described in this question. However get following error
I'm using the method described by Josh in this question to add a toolbar
I'm using an invocation described in this question: Synchronization accross threads / atomic checks?
Given: File f = new File(test.txt); this way, each time i create a reference
I am using CAGradientLayer to create a background layer, as described in this answer
I want to do what's described in question 724043 , namely encode the path
The question is as described here: Knight's Shortest Path Chess Question . I tried
I have a question which is described below: What problems would arise for testing
I have the same question problem as described here How to purge a cached

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.