0

I am building a site creation script in PowerShell working good for now.

I added a part to create lists and add to navigation depending on what kind of site is selected.

`

          Connect-PnPOnline -Url $NewSiteUrl -Credentials $cred
            New-PnPList -Title Newsfeed -Template DiscussionBoard
            New-PnPList -Title Tasks -Template Tasks
            New-PnPList -Title Contacts -Template Contacts
            New-PnPList -Title Calendar -Template Events
            New-PnPList -Title Links -Template Links 
            Add-PnPNavigationNode -Title "Newsfeed" -Url "$NewSiteUrl/Lists/Newsfeed" -Location "QuickLaunch"
            Add-PnPNavigationNode -Title "Tasks" -Url "$NewSiteUrl/Lists/Tasks" -Location "QuickLaunch"
            Add-PnPNavigationNode -Title "Contacts" -Url "$NewSiteUrl/Lists/Contacts" -Location "QuickLaunch"
            Add-PnPNavigationNode -Title "Calendar" -Url "$NewSiteUrl/Lists/Calendar" -Location "QuickLaunch"
            Add-PnPNavigationNode -Title "Links" -Url "$NewSiteUrl/Lists/Links" -Location "QuickLaunch"
            Add-PnPNavigationNode -Title "Manage Site Access" -Url "$NewSiteUrl/_layouts/groups.aspx" -Location "QuickLaunch"

` While the script runs I get this error when it goes through this section:

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. + CategoryInfo : NotSpecified: (:) [format-default], CollectionNotInitializedException + FullyQualifiedErrorId : Microsoft.SharePoint.Client.CollectionNotInitializedException,Microsoft.PowerShell.Commands.FormatDefaultCommand

When the script stops, if I go back and select the code and run Selection in PowerShell it will go ahead (sometimes) and create all the list and add them to the navigation.

I tried putting each line into a variable and calling it, also tried to put a start-sleep 15 between each library creation but it errors out still.

1

You can use Out-Null to remove the output from the pipeline:

Connect-PnPOnline -Url $NewSiteUrl -Credentials $cred

New-PnPList -Title Newsfeed -Template DiscussionBoard | Out-Null
New-PnPList -Title Tasks -Template Tasks | Out-Null
New-PnPList -Title Contacts -Template Contacts | Out-Null
New-PnPList -Title Calendar -Template Events | Out-Null
New-PnPList -Title Links -Template Links | Out-Null
Add-PnPNavigationNode -Title "Newsfeed" -Url "$NewSiteUrl/Lists/Newsfeed" -Location "QuickLaunch"
Add-PnPNavigationNode -Title "Tasks" -Url "$NewSiteUrl/Lists/Tasks" -Location "QuickLaunch"
Add-PnPNavigationNode -Title "Contacts" -Url "$NewSiteUrl/Lists/Contacts" -Location "QuickLaunch"
Add-PnPNavigationNode -Title "Calendar" -Url "$NewSiteUrl/Lists/Calendar" -Location "QuickLaunch"
Add-PnPNavigationNode -Title "Links" -Url "$NewSiteUrl/Lists/Links" -Location "QuickLaunch"
Add-PnPNavigationNode -Title "Manage Site Access" -Url "$NewSiteUrl/_layouts/groups.aspx" -Location "QuickLaunch"

Or put the lists in a csv file to loop through with if you have too many.

References:

format-default: the collection has not been initialized on Add-PnPFile after Apply-PnPProvisioning is Run.

SharePoint Online: Create Multiple Lists from a CSV File using PowerShell.

3
  • Perfect this did the trick. thanks for the help! – Breau Oct 6 '20 at 13:23
  • @Breau Glad it helps. Would you please accept it as answer if you confirm the problem is solved? It will help others in this forum to find answers quickly as well. Thanks. – Chelsea_MSFT Oct 6 '20 at 23:12
  • sure thing sorry about that. – Breau Oct 7 '20 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.