Closed janegilring closed 6 years ago
Can you post an example of your Add-PnPFile working? I'm wondering...is C:\temp\test.txt a file on your local machine or stored somewhere in Azure?
Working example: Add-PnPFile -Path C:\Temp\test.txt -Folder "folder1/subfolder" -ErrorAction Ignore
C:\temp\test.txt is located on a Windows Server 2016 machine, which is a regular Windows Server with Microsoft Monitoring Agent installed that makes it able to accept PowerShell runnbook jobs from an Azure Automation account (so called Hybrid Runbook Worker).
Same issue here, I'm unable to use Add-PnPFile within an Azure Automation runbook. The workaround isn't working for me. The workbook is retried 3 times and then suspended.
Had the same issue here. Downgrading to 2.16. something as Jan mentioned did not work.
A workaround that did fix my issue is assigning the add-pnpfile output to a variable
$dummy = Add-PnpFile -Path $file -Folder $folder see #722
Thanks Stijnc, I can confirm this workaround fixed my issue too #happy.
FYI: I now see that I am in fact assigning output to $null, so the -ErrorAction Ignore workaround might have been a coincidence during troubleshooting.
The reason this error occurs is due to the outpput formatting we do behind the scenes. I've identified the location and will commit a fix to it.
I merged the commit and will close this issue for now. The fix will be available in the upcoming April release.
thanks!
I'm still experiencing the issue, could you reinvestigate this? Also, the file is not visible on the SharePoint website after uploading it (I have waited a few hours), but you can download it by visiting the URL manually.
Add-PnPFile -Path $localHostPath -Folder $SharePointFolder
Forwarding to Out-Null
fixes the problem.
Reporting an Issue or Missing Feature
After running Add-PnPFile, the specified file is successfully uploaded to the specified Sharepoint folder, but an error is being generated silently.
Expected behavior
The specified file should be uploaded to the specifed Sharepoint folder without errors being generated.
Actual behavior
The specified file is uploaded to the specifed Sharepoint folder. However, $Error is populated with an exception after running Add-PnpFile.
Steps to reproduce behavior
1) Clear $Error $Error.Clear() 2) Verify that $Error is empty $Error 3) Run Add-PnPFile Add-PnPFile -Path C:\Temp\test.txt -Folder "folder1/subfolder" 4) Inspect $Error and notice the exception: $Error You cannot call a method on a null-valued expression. At line:1 char:1
I noticed this issue when using the cmdlet in an Azure Automation runbook. The runbook would fail to upload the generated error message and restart. After 3 re-tries the runbook goes into a Suspended mode. To workaround this issue, I added -ErrorAction -Ignore to Add-PnPFile.
The full error message from the Azure Automation job:
inner exception -> Microsoft.SharePoint.Client.CollectionNotInitializedException: The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. at Microsoft.SharePoint.Client.ClientObjectCollection.d__0.MoveNext()
at Microsoft.PowerShell.Commands.Internal.Format.PSObjectHelper.SmartToString(PSObject so, MshExpressionFactory expressionFactory, Int32 enumerationLimit, StringFormatError formatErrorObject)
at Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator.GetExpressionDisplayValue(PSObject so, Int32 enumerationLimit, MshExpression ex, FieldFormattingDirective directive, MshExpressionResult& expressionResult)
at Microsoft.PowerShell.Commands.Internal.Format.ListViewGenerator.GenerateListViewEntryFromProperties(PSObject so, Int32 enumerationLimit)
at Microsoft.PowerShell.Commands.Internal.Format.ListViewGenerator.GeneratePayload(PSObject so, Int32 enumerationLimit)
at Microsoft.PowerShell.Commands.Internal.Format.InnerFormatShapeCommand.WritePayloadObject(PSObject so)
at Microsoft.PowerShell.Commands.Internal.Format.InnerFormatShapeCommand.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
]
Which version of the PnP-PowerShell Cmdlets are you using?
What is the version of the Cmdlet module you are running?
(you can retrieve this by executing
Get-Module -Name *pnppowershell* -ListAvailable
) 2.16.1706.1How did you install the PnP-PowerShell Cmdlets?