{"id":2807,"date":"2020-01-31T16:38:00","date_gmt":"2020-01-31T15:38:00","guid":{"rendered":"https:\/\/www.itidea.nl\/?p=2807"},"modified":"2020-02-06T15:02:29","modified_gmt":"2020-02-06T14:02:29","slug":"pnp-powershell-format-default-error","status":"publish","type":"post","link":"https:\/\/www.itidea.nl\/index.php\/pnp-powershell-format-default-error\/","title":{"rendered":"PnP PowerShell Format-default error"},"content":{"rendered":"\n<p>It was a while ago when I saw the error<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>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.<\/p><\/blockquote>\n\n\n\n<p>I came to my attention again when a script was created which created multiple webs using New-PNPWeb, applied a provisioning template using Apply-PNPProvisioningTemplate, added some fields, lists, views and listitems with their corresponding PnP PowerShell cmdlets.<br>Sometimes the error &#8216;format-default&#8217; occurs running the script, but not always and not always at the same line of code.<\/p>\n\n\n\n<p>PowerShell&#8217;s default behaviour is to output the returned value to the console. <br> So when running a cmdlet like Add-PnPListItem the returned value is visible in the console.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"328\" height=\"80\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2020\/02\/PS_AddPnPListItem.png\" alt=\"\" class=\"wp-image-2808\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2020\/02\/PS_AddPnPListItem.png 328w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2020\/02\/PS_AddPnPListItem-300x73.png 300w\" sizes=\"auto, (max-width: 328px) 100vw, 328px\" \/><\/figure>\n\n\n\n<p>Probably some PnP cmdlets output an object where one of the properties has not been loaded by CSOM. By assigning the output to a variable the error message is kind of suppressed and the resulting object is stored in the variable.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$fix = Add-PnPView ...<\/code><\/pre>\n\n\n\n<p>When you output the\nvariable to the console the error message will be shown again.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>When you experience\nthe error &#8216;format-default\u2026&#8217; provisioning a site with PnP PowerShell the\nsolution is to always store the return value in a variable.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It was a while ago when I saw the 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. I came to &#8230; <a class=\"more-link\" href=\"https:\/\/www.itidea.nl\/index.php\/pnp-powershell-format-default-error\/\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39,22,41],"tags":[37,43,46],"class_list":["post-2807","post","type-post","status-publish","format-standard","hentry","category-office-365","category-powershell","category-sharepoint","tag-office365","tag-powershell","tag-sharepoint"],"_links":{"self":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/2807","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/comments?post=2807"}],"version-history":[{"count":3,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/2807\/revisions"}],"predecessor-version":[{"id":2811,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/2807\/revisions\/2811"}],"wp:attachment":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/media?parent=2807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/categories?post=2807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/tags?post=2807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}