Skip to content

Instantly share code, notes, and snippets.

@reshmee011
Last active August 26, 2016 10:19
Show Gist options
  • Save reshmee011/dfe0b6fa3eb3d8f59e9d0415f66662d7 to your computer and use it in GitHub Desktop.
Save reshmee011/dfe0b6fa3eb3d8f59e9d0415f66662d7 to your computer and use it in GitHub Desktop.
Param(
[Parameter(Mandatory=$true)]
[string]$SiteUrl,
[Parameter(Mandatory=$true)]
[string]$username,
[Parameter(Mandatory=$false)]
[string]$ListName = "Documents"
)
#retrieve MigrationSourceURL and breaks it down into level 0 and level 1 and retrieve term from URL to map to column
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
##$username = Read-Host -Prompt "Enter userName";
$Adminpassword = Read-Host -Prompt "Enter password" -AsSecureString ;
$spContext = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl);
$spContext.Credentials = New-Object System.Net.NetworkCredential($username, $Adminpassword);
$web = $spContext.Web;
$Lists = $web.Lists;
$spContext.Load($web);
$spContext.Load($Lists);
$spContext.ExecuteQuery();
## get the composite look gallery to create composed look
$docList = $Lists.GetByTitle($ListName)
$spContext.Load($docList);
$spContext.ExecuteQuery();
# This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll"
# so that it grabs all list items, regardless of the folder they are in.
$query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery(100)
$items = $docList.GetItems($query)
$spContext.Load($items)
$spContext.ExecuteQuery()
$items|ForEach-Object{
$sourceUrl = $_["MigrationSourceURL"];
$level0= Split-Path -parent $sourceUrl
$level0 = Split-Path (Split-Path $sourceUrl -Parent) -Leaf
$level1= Split-Path ($sourceUrl | split-path -parent | split-path -parent) -Leaf
$_["Level0"] = $level0;
$_["Level1"] = $level1;
$_.Update();
$spContext.ExecuteQuery()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment