Create or update Json file in Sharepoint Online Document library | Add-PnPFile : Cannot bind parameter 'Stream'. Cannot convert the value of type "System.String" to type "System.IO.Stream".

Hitender Singh 131 Reputation points
2021-05-24T15:19:45.157+00:00

Hello,

I am trying to fetch data and update data from a JSON file stored in SPO using a azure runbook. So far I am able to fetch data and use it in the powershell script/runbook but I am unable to create a new json file or update it.

Fetching data:-

![99087-image.png]2

I am unable to create a new json file or any file in document library

99120-image.png

Microsoft 365 and Office | SharePoint Server | For business
Microsoft 365 and Office | SharePoint | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Answer accepted by question author
  1. MichaelHan-MSFT 18,136 Reputation points
    2021-05-25T03:17:06.6+00:00

    Hi @Hitender Singh ,

    What's the type of parameter $a? Is it a string? If so you need to convert it to Stream type to make it work. Below is my demo code for you:

    $a='[  
        {  
            "test": "A",  
            "id": 1  
        },  
        {  
            "test": "B",  
            "id": 2  
        },  
        {  
            "test": "C",  
            "id": 3  
        }  
    ]'  
    $stream = [IO.MemoryStream]::new([Text.Encoding]::UTF8.GetBytes($a))  
    Add-pnpfile -Folder "Shared Documents" -FileName "test.json" -Stream $stream  -Values @{Modified="1/5/2021"}  
    

    99287-image.png


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.