Skip to content

Instantly share code, notes, and snippets.

@star-crossed
Created April 18, 2017 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save star-crossed/ed78de21cf529219f4dd78f6462ca0d0 to your computer and use it in GitHub Desktop.
Save star-crossed/ed78de21cf529219f4dd78f6462ca0d0 to your computer and use it in GitHub Desktop.
PowerShell script for SharePoint using CSOM to take a list column and "promote" it to a site column.
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, HelpMessage="This is the URL to the SharePoint Online site.")]
[string]$Url,
[Parameter(Mandatory=$false, HelpMessage="This is the path to the DLLs for CSOM.")]
[string]$CSOMPath
)
Set-Strictmode -Version 1
If ($CSOMPath -eq $null -or $CSOMPath -eq "") { $CSOMPath = "." }
Add-Type -Path "$CSOMPath\Microsoft.SharePoint.Client.dll"
Add-Type -Path "$CSOMPath\Microsoft.SharePoint.Client.Runtime.dll"
$psCredentials = Get-Credential
$spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($psCredentials.UserName, $psCredentials.Password)
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$clientContext.Credentials = $spoCredentials
$domain = ([System.Uri]$Url).Host
$userName = $psCredentials.UserName
If ($clientContext.ServerObjectIsNull.Value) {
Write-Error "Could not connect to SharePoint Online site collection: $Url"
} Else {
Write-Host "Connected to SharePoint Online site collection: " $Url -ForegroundColor Green
$web = $clientContext.Web
$clientContext.Load($web)
$clientContext.Load($web.SiteGroups)
$clientContext.ExecuteQuery()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment