How to convert a string to a stream object in Powershell?

Question:

I want to make a string fit for consumption as a stream, by e.g. Get-FileHash command (using its -InputStream parameter).

The reason I want this is that I need to digest a string, and not contents of a file. I do not want to temporarily store said string in a file just to digest it.

I know this can be done with some half a dozen .NET objects, which is trivially supported by Powershell, but I am just curious whether there is an existing PS command or combination thereof that turns a string object into a stream, so I can do something like the following (assuming the hypothetical Convert turns the string into a stream)?

Answer:

You can use some .NET functions:

Source:

How to convert a string to a stream object in Powershell? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply