{"id":425,"date":"2022-11-23T15:45:57","date_gmt":"2022-11-23T14:45:57","guid":{"rendered":"https:\/\/www.paalolav.no\/?p=425"},"modified":"2023-04-19T14:18:32","modified_gmt":"2023-04-19T12:18:32","slug":"changing-the-search-scope-in-sharepoint","status":"publish","type":"post","link":"https:\/\/www.paalolav.no\/?p=425","title":{"rendered":"Changing the Search scope in SharePoint"},"content":{"rendered":"\n<p>When a customer with tons of sites needs to change the search scope, there are several ways to approach this. <\/p>\n\n\n\n<p>One solution is to create a PnP PowerShell script. In this example we&#8217;ll change the search scope to tenant (Organization).<\/p>\n\n\n\n<p><strong>Steps to success:<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.paalolav.no\/wp-content\/uploads\/2022\/11\/Export.png\"><img loading=\"lazy\" decoding=\"async\" width=\"555\" height=\"173\" src=\"https:\/\/www.paalolav.no\/wp-content\/uploads\/2022\/11\/Export.png\" alt=\"\" class=\"wp-image-426\" srcset=\"https:\/\/www.paalolav.no\/wp-content\/uploads\/2022\/11\/Export.png 555w, https:\/\/www.paalolav.no\/wp-content\/uploads\/2022\/11\/Export-300x94.png 300w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/a><figcaption class=\"wp-element-caption\">Export list of sites as a CSV-file<\/figcaption><\/figure>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a service account with SharePoint Administrator privileges.<\/li>\n\n\n\n<li>Download a list of all the sites on your tenant from the SharePoint admin panel as a CSV-file (Export). If you need to exclude sites, this is the time to do it &#8211; remove the sites you don&#8217;t want to touch from the downloaded list.<\/li>\n\n\n\n<li>If there are several hundred sites, split your CSV file and do the next step in chunks.<\/li>\n\n\n\n<li>Edit the fields CSVPath, ServiceAccount and TenantName in the script below.<\/li>\n\n\n\n<li> Run the script and login from the service account when prompted.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>#Set Parameters\n$CSVPath = \".\/AllSites.csv\"\n$ServiceAccount = \"username@tenantname.no\"\n$TenantName = \"tenantname\"\n\n#Fetch sites from the CSV file\n$SiteList = Import-CSV $CSVPath\n\n$i = 0;\n$TotalRecords = $SiteList.Count\n\nConnect-PnPOnline -Url https:\/\/$TenantName-admin.sharepoint.com\/ -Interactive\n#Iterate through each row from the CSV-file and deploy in script.\ntry {\nForEach ($Record in $SiteList)\n{\n$i++;\nWrite-Progress -activity \"Adding Site '$($Record.'Url')'\" -status \"$i out of $TotalRecords completed\"\n\nSet-PnPTenantSite -Identity $Record.'URL' -Owners \"$ServiceAccount\"\nConnect-PnPOnline -Url $Record.'URL' -Interactive\n\n#change default search scope\nSet-PnPSearchSettings -SearchScope Tenant -SearchBoxPlaceholderText \"S\u00f8k her...\"\nRemove-PnPSiteCollectionAdmin -Owners \"$ServiceAccount\"\n}\n}\ncatch {\n\tWrite-Host \"There was an error, see details below:\"\n\tWrite-Host $_\t\/\/Print the potential errors\n}<\/code><\/pre>\n\n\n\n<p><strong>Drink some coffee and enjoy your new search scope.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When a customer with tons of sites needs to change the search scope, there are several ways to approach this. One solution is to create a PnP PowerShell script. In this example we&#8217;ll change the search scope to tenant (Organization). Steps to success: Drink some coffee and enjoy your new search scope.<\/p>\n","protected":false},"author":2,"featured_media":426,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77,67,76],"tags":[],"class_list":["post-425","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft","category-sharepoint","category-search"],"_links":{"self":[{"href":"https:\/\/www.paalolav.no\/index.php?rest_route=\/wp\/v2\/posts\/425"}],"collection":[{"href":"https:\/\/www.paalolav.no\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.paalolav.no\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.paalolav.no\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.paalolav.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=425"}],"version-history":[{"count":6,"href":"https:\/\/www.paalolav.no\/index.php?rest_route=\/wp\/v2\/posts\/425\/revisions"}],"predecessor-version":[{"id":435,"href":"https:\/\/www.paalolav.no\/index.php?rest_route=\/wp\/v2\/posts\/425\/revisions\/435"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.paalolav.no\/index.php?rest_route=\/wp\/v2\/media\/426"}],"wp:attachment":[{"href":"https:\/\/www.paalolav.no\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.paalolav.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.paalolav.no\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}