Recently, we did eRoom to SharePoint 2013 migration with the help of Metalogix. When you migrate eRoom content to SharePoint, Metalogix eRoom console by default add ‘MigrationSourceUrl’ column to every list and library created during migration. This column contains source eRoom object URL from where this object is migrated. The value in this column is useful from mapping perspective and link correction perspective. In Metalogix you can't avoid creating this column in target SharePoint. Though in our case, end user don’t want to see this column by default in SharePoint. So we decided to hide this column from ‘Default’ list/library view after migration is complete. This was again a task which involves lot of manual efforts. Ultimate choice was to create PowerShell script which could be re-used now and in future. What if it is Remote PowerShell? It provides added advantage that you don’t have to login to CA box and run the script and also no burden on your server.
Pre-requisite:
- Client side Remote PowerShell.
- A .csv file if script needs to run on multiple sites (SPWeb).
- User credentials who has administrative access to the sites/environment.
Details
The script first understands the target SharePoint scope like Site Collection, Site or List of Sites based on user inputs. It also tries to understand if current user has access to the target SharePoint environment. Based on user inputs, it takes various approaches to get list of webs and list of Lists.
- CLS
- Write-Host "`t ----------------------------------------------------------------"
- Write-Host "`t Hide Migration Source URL column from List View for eRoom Migration SharePoint Sites"
- Write-Host "`t ----------------------------------------------------------------"
- Write-Host -ForegroundColor Magenta "`t `t Choose target SharePoint environment"
- Write-Host -ForegroundColor Cyan "`t `t `t 1. Office 365"
- Write-Host -ForegroundColor Cyan "`t `t `t 2. SharePoint 2013"
- Write-Host -ForegroundColor Cyan "`t `t `t 3. SharePoint 2010"
- $envChoice = Read-Host "Select an option 1-3 "
- switch($envChoice)
- {
- 1{$targetScope = "Office365"}
- 2{$targetScope = "SharePoint2013"}
- 3{$targetScope = "SharePoint2010"}
- }
- Write-Host
- Write-Host -ForegroundColor Magenta "`t Select the scope of the script excution"
- Write-Host -ForegroundColor Cyan "`t `t 1. Site"
- Write-Host -ForegroundColor Cyan "`t `t 2. Web"
- Write-Host -ForegroundColor Cyan "`t `t 3. List of Web (CSV Path Input)"
- $scopeChoice = Read-Host "Enter your choice"
- #User Credentials
- Write-Host -ForegroundColor Magenta "`t `t Do you have access to "$targetScope " environment"
- Write-Host -ForegroundColor Cyan "`t `t `t 1. Yes"
- Write-Host -ForegroundColor Cyan "`t `t `t 2. No. Provide alternate user credentials (domain\login)"
- $accessChoice = Read-Host "Select an option 1-2"
- Write-Host "accessChoice:"$accessChoice
- switch($accessChoice)
- {
- 1{$accessScope = "HasAccess"}
- 2{$accessScope= "NoAccess"}
- default{$accessScope ="HasAccess"}
- }
- $credentials = $null
- #Getting user credentials
- if($accessScope -eq "NoAccess")
- {
- $credentials = Get-Credential -Credential (whoami)
- }
- $IsSite = $false
- $csvFilePath = $null
- $csvSPWebList = @()
- switch ($scopeChoice)
- {
- 1 { $scope = "Site"}
- 2 { $scope ="Web"}
- 3 { $scope = "WebList"}
- }
- if($scope -eq "Site")
- {
- $targetUrl = Read-Host "Enter Site Collection Url"
- if($targetScope -eq "Office365")
- {
- Hide-MigrationSourceUrl -WebUrl $targetUrl -IsOnline $true -IsSite $true
- }
- elseif($targetScope -eq "SharePoint2013")
- {
- Hide-MigrationSourceUrl -WebUrl $targetUrl -UserCredential $credentials -IsSite $true
- }
- elseif($targetScope -eq "SharePoint2010")
- {
- Hide-MigrationSourceUrl -WebUrl $targetUrl -UserCredential $credentials -IsSite $true -Is2010 $true
- }
- }
- elseif($scope -eq "Web")
- {
- $IsSite = $false
- $targetUrl = Read-Host "Enter Web Url"
- if($targetScope -eq "Office365")
- {
- Hide-MigrationSourceUrl -WebUrl $targetUrl -IsOnline $true -IsSite $false
- }
- elseif($targetScope -eq "SharePoint2013")
- {
- Hide-MigrationSourceUrl -WebUrl $targetUrl -UserCredential $credentials -IsSite $false
- }
- elseif($targetScope -eq "SharePoint2010")
- {
- Hide-MigrationSourceUrl -WebUrl $targetUrl -UserCredential $credentials -IsSite $false -Is2010 $true
- }
- }
- elseif($scope -eq "WebList")
- {
- $IsSite = $false
- while($csvFilePath -eq $null)
- {
- try
- {
- #reading .csv file
- $csvFilePath = Read-Host "Enter path of .csv file which contains SPWeb Urls"
- $csvContent = Import-Csv -Path $csvFilePath -ErrorAction Stop
- if($csvContent -ne $null)
- {
- Write-Host "No. of Entries found:"$csvContent.Count
- foreach($entry in $csvContent)
- {
- $csvWebUrl = $entry.WebUrl
- Write-Host "Processing Web:"$csvWebUrl
- if($targetScope -eq "Office365")
- {
- Hide-MigrationSourceUrl -WebUrl $csvWebUrl -IsOnline $true -IsSite $false
- }
- elseif($targetScope -eq "SharePoint2013")
- {
- Hide-MigrationSourceUrl -WebUrl $csvWebUrl -UserCredential $credentials -IsSite $false
- }
- elseif($targetScope -eq "SharePoint2010")
- {
- Hide-MigrationSourceUrl -WebUrl $csvWebUrl -UserCredential $credentials -IsSite $false -Is2010 $true
- }
- }
- }
- }
- catch
- {
- $csvFilePath = $null
- Write-Host -ForegroundColor Red "Error:"$_.Exception.Message "Please try again."
- Write-Host
- }
- }
- }
Santhakumar MunuswamyPosted Oct 18, 2015, 3:48 AM
Good one
Mukesh KumarPosted Oct 13, 2015, 1:55 AM
Great Job...Thanks
Harshad PansuriyaPosted Oct 13, 2015, 12:18 AM
Nice one
Nilesh JadavPosted Oct 13, 2015, 12:07 AM
Nice share sir