Skip to content

Instantly share code, notes, and snippets.

@firstval
Forked from chrisobriensp/TopOfScript_PSCSOM.ps1
Last active August 29, 2015 14:16
Show Gist options
  • Save firstval/2bde38c9878e91b1b28a to your computer and use it in GitHub Desktop.
Save firstval/2bde38c9878e91b1b28a to your computer and use it in GitHub Desktop.
# replace these details (also consider using Get-Credential to enter password securely as script runs)..
$username = "SomeUser@SomeOrg.onmicrosoft.com"
$password = "SomePassword"
$url = "https://SomeSite.sharepoint.com"
$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
# the path here may need to change if you used e.g. C:\Lib..
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"
# note that you might need some other references (depending on what your script does) for example:
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"
# connect/authenticate to SharePoint Online and get ClientContext object..
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$clientContext.Credentials = $credentials
if (!$clientContext.ServerObjectIsNull.Value)
{
Write-Host "Connected to SharePoint Online site: '$Url'" -ForegroundColor Green
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment