Open kritschg opened 5 years ago
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
using Get-PnPFile and Set-PnPListItem in the same script throws the following error: format-default : 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.
the script initially checked a sharepoint list item, if the status was set to a certain value it would download the attachment, upload it to azure blob storage and set the list item to a new status.
The workaround is to do the download/upload in one script and in a separate script to the list item update
here is the code, originally there was one foreach loop but I separated them to troubleshoot the issue: Connect-AzAccount -Credential $creds -Subscription "Cloud Trust NonProd" $ResourceGroup = Get-AzResourceGroup -Name $StorageAccount = Get-AzStorageAccount -Name -ResourceGroupName $ResourceGroup.ResourceGroupName $ctx = $StorageAccount.Context $container=Get-AzStorageContainer -Name "networkdiagrams" -Context $CTX Connect-PnPOnline -Url -Credentials $creds
$list = Get-PnPList SiteNetworkDiagrams $items = $list | Get-PnPListItem
foreach ($item in $items) { $item.FieldValues.Title switch ($item.FieldValues.Status) { "Uploaded"{"do nothing"} "New" { "new"
$attachments = ForEach-Object{Get-PnPProperty -ClientObject $item -Property "AttachmentFiles"}
Get-PnPFile -Url $attachments.ServerRelativeUrl -FileName $attachments.FileName -Path "E:\NetDiagrams\" -AsFile -Force
$filename = $item.FieldValues.Title + ".png"
$filepath = "E:\NetDiagrams\" + $attachments.FileName
Set-AzStorageBlobContent -File $filepath -Container $container.Name -AsJob -Blob $filename -Context $ctx -Confirm:$false -Force
}
"Updated"
{
"updated"
#Set-PnPListItem -List "SiteNetworkDiagrams" -Identity $item.Id -Values @{"Status" = "Uploaded"}
$attachments = ForEach-Object{Get-PnPProperty -ClientObject $item -Property "AttachmentFiles"}
Get-PnPFile -Url $attachments.ServerRelativeUrl -FileName $attachments.FileName -Path "E:\NetDiagrams\" -AsFile -Force
$filename = $item.FieldValues.Title + ".png"
$filepath = "E:\NetDiagrams\" + $attachments.FileName
Set-AzStorageBlobContent -File $filepath -Container $container.Name -AsJob -Blob $filename -Context $ctx -Confirm:$false -Force
}
}
}
Connect-PnPOnline -Url https:// -Credentials $creds $list = Get-PnPList SiteNetworkDiagrams $items = $list | Get-PnPListItem foreach ($item in $items) { $item.FieldValues.Title switch ($item.FieldValues.Status) { "Uploaded"{"do nothing"} "New" { "new" Set-PnPListItem -List "SiteNetworkDiagrams" -Identity $item.Id -Values @{"Status" = "Uploaded"} } "Updated" { "updated" Set-PnPListItem -List "SiteNetworkDiagrams" -Identity $item.Id -Values @{"Status" = "Uploaded"} } } }
Notice: many issues / bugs reported are actually related to the PnP Core Library which is used behind the scenes. Consider carefully where to report an issue:
Apply-SPOProvisioningTemplate
orGet-SPOProvisioningTemplate
? The issue is most likely related to the Provisioning Engine. The Provisioning engine is not located in the PowerShell repo. Please report the issue here: https://github.com/officedev/PnP-Sites-Core/issues.Reporting an Issue or Missing Feature
Please confirm what it is that your reporting
Expected behavior
Please describe what output you expect to see from PnP-PowerShell Cmdlets
Actual behavior
Please describe what you see instead. Please provide samples of HTML output or screenshots
Steps to reproduce behavior
Please include complete code samples in-line or linked from gists
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
)How did you install the PnP-PowerShell Cmdlets?