0

Trying to write a simple PowerShell script, but got stuck with an error, and I can't find any solution on the web.

$stream = [IO.MemoryStream]::new([Text.Encoding]::UTF8.GetBytes('aaaaaaaaaa!'))
Get-FileHash -InputStream $stream -Algorithm SHA512
AddPnPFile -Path './bundle.json' -Folder "$($FolderRelativeURLGeneral)$($folder)" -Stream $stream

Why am I getting an error for providing a stream to the Stream parameter? Removing the parameter solved the issue, but obviously I want to write something to the file, so can someone tell me how to write content to the file? Do I need to create a filestream out of the stream? However, the documentation doesn't specify that it has to be a file stream. How come it doesn't work?

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

1
  • what is the exact error? PoSh errors usually have a good deal of useful info ... [grin] add it to your Question, not in the comments ... and please use code formatting so it will be easily readable. Commented Mar 9, 2020 at 20:35

1 Answer 1

1

In PowerShell, a parameter set specifies which parameters can be used together when calling a function.

You can use parameters from one set or another set, you cannot mix and match.

Checking the documentation for Add-PnPFile, Path and Folder are part of one parameter set, while Folder and Stream are part of another; there is no parameter set that has all 3 parameters.

I think you're looking for FileName (which i assume creates a file from the stream) instead of Path (which is a local file path).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.