The last few months I’ve been involved in a lot of SharePoint migrations. Most of these migrations are in on premise environment and involve moving large amounts of sites. As part of the migration process it is important to get the migrated content checked. When it involves large amount of content, it gets time consuming to check everything. As migrator you do not have the time and more importantly, you are not aware of all the important pieces of content within a site. Therefore it is handy to get the business owners involved.
With lots of sites, it is difficult to manually create a list of these business owners. When a business owner is responsible for the content of a site, he or she is most likely one of the site owners.
The following PowerShell script iterates through all the sites within a web application and enumerates per site the site owners. The list contains the title, the old URL, the new URL and per site owner its name and e-mail. Due to the delimiter used it’s easy to import the file into Excel. Send the list to all the site owners and let them check the content for the sites they are responsible for.
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") $webAppOldUrl = "http://www.old-contoso.com"; $webAppUrl = "http://www.contoso.com"; function IterateSubSites($site) { foreach($subSite in $site.Webs) { $urlName = $subSite.Url $urlName = $urlName.SubString($urlName.LastIndexOf("/") + 1) $outtext = $subSite.Title + "|" + $urlName + "|" + $webAppOldUrl "/" + $subSite.Url + "|" + $webAppUrl + "/" + $subSite.Url; foreach($group in $subSite.Groups) { if($group.Name -like "*Owners*") { foreach($user in $group.Users) { $outtext = $outtext + $user.Name + "(" + $user.Email + "); " } } } Write-Host $outtext $outtext | Out-File c:SiteOwnerList.txt -Append IterateSubSites($subSite); } } $webApp = Get-SPWebApplication $webAppUrl foreach($site in $webApp.Sites) { IterateSubSites($site.RootWeb) }
The PowerShell script is based on existing scripts found on the internet. It is altered for the purpose of generating business owner lists for migration projects. Feel free to copy and use the script.
Hello.
First there is a / missing in
$webAppOldUrl “/”
Job fails:
PS C:\temp> .\SpOwner.ps1
Get-SPWebApplication : The term ‘Get-SPWebApplication’ is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At C:\temp\SpOwner.ps1:31 char:11
+ $webApp = Get-SPWebApplication $webAppUrl
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-SPWebApplication:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
So looks the procedure is not visible …