Add-PnPFile 流输出中的无效字符

Invalid Characters in Add-PnPFile stream output

我正在尝试获取一个字符串并将其写入 SharePoint Online 中的新文件(或更新现有文件)。使用以下代码,创建了文件,但它充满了无效字符(菱形内的?)并且没有出现字符串“test string”。

$RootPath = '/Shared Documents/General'
$FolderName = 'Customer'
$FileName = 'test.txt'
$fileContent = 'test string'
$Size = 8192;
[System.IO.MemoryMappedFiles.MemoryMappedFile]$MMF = [System.IO.MemoryMappedFiles.MemoryMappedFile]::CreateNew($FileName, $Size);
If ($Null -eq $MMF) {
    Return;
}
$Stream = $MMF.CreateViewStream();
$StreamWriter = [System.IO.StreamWriter]::new($Stream);
$StreamWriter.Write($FileContent);
Add-PnPFile -FileName $FileName -Folder "$RootPath/$FolderName" -Stream $Stream
$StreamWriter.Dispose();
$Stream.Dispose();
$MMF.Dispose();

是我对字符串的编码不正确还是什么?

示例脚本供您参考。

#region Variables 
$Username = "user@xxx.onmicrosoft.com" 
$Password = "Password" 
$siteURL = "https://xxx.sharepoint.com/sites/lee" 
#endregion Variables

#region Credentials 
[SecureString]$SecurePass = ConvertTo-SecureString $Password -AsPlainText -Force 
[System.Management.Automation.PSCredential]$PSCredentials = New-Object System.Management.Automation.PSCredential($Username, $SecurePass) 
#endregion Credentials

Connect-PnPOnline -Url $siteURL -Credentials $PSCredentials

$RootPath = '/Shared Documents/General'
$FolderName = 'Customer'
$FileName = 'test.txt'
$fileContent = 'test string'

$Stream = [IO.MemoryStream]::new([Text.Encoding]::UTF8.GetBytes($fileContent))

# $Size = 8192;
# [System.IO.MemoryMappedFiles.MemoryMappedFile]$MMF = [System.IO.MemoryMappedFiles.MemoryMappedFile]::CreateNew($FileName, $Size);
# If ($Null -eq $MMF) {
#     Return;
# }
# $Stream = $MMF.CreateViewStream();
# $StreamWriter = [System.IO.StreamWriter]::new($Stream);
# $StreamWriter.Write($FileContent);

Add-PnPFile -FileName $FileName -Folder "$RootPath/$FolderName" -Stream $Stream

# $StreamWriter.Dispose();
# $Stream.Dispose();
# $MMF.Dispose();

Write-Host "----"