Using the SharePointPnPPowerShellOnline module, to upload a file, to a specific folder (in a specific site), I used to run commands like this:
$cred = Get-Credential
Connect-PnPOnline -Url "https://<company>.sharepoint.com/sites/<site name>" -Credentials $cred -ErrorAction Stop
$memStream = [System.IO.MemoryStream]([System.Text.Encoding]::UTF8.GetBytes(($data | ConvertTo-Csv -NoTypeInformation)))
Add-PnPFile -FileName $fileName -Folder "/Shared Documents/<folder>/<sub folder>" -Stream $memStream -ErrorAction Stop
Since SharePointPnPPowerShellOnline is being replaced by PnP.PowerShell, I tried running the same command in with the new module installed. After adding the required consent (Register-PnPManagementShellAccess), I got the error:
Connect-PnPOnline : The remote server returned an error: (403) Forbidden.
I changed the connect command to:
Connect-PnPOnline -Url "https://<company>.sharepoint.com/" -Credentials $cred -ErrorAction Stop
That seemed to work:
VERBOSE: Acquiring token
VERBOSE: Token acquired VERBOSE: PnP
PowerShell Cmdlets (1.10.0.0)
When I ran the Add-PnPFile command again, there were no errors, but I cannot find the file in SharePoint. What am I missing here?