Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 34890

The first steps

$
0
0

The very first steps to connect to Sharepoint Online with Powershell are:

  • load the required dlls for your operation ( you will need at a minimum Microsoft.SharePoint.CLient.dll and Microsoft.SharePointClient.Runtime.dll)
  • establish a client context to the site where you want to work

Loading the dlls:

if you installed Sharepoint Online Management Shell :

 

$programFiles = [environment]::getfolderpath("programfiles")
add-type -Path $programFiles'SharePoint Online Management ShellMicrosoft.Online.SharePoint.PowerShellMicrosoft.SharePoint.Client.dll'
add-type -Path $programFiles'SharePoint Online Management ShellMicrosoft.Online.SharePoint.PowerShellMicrosoft.SharePoint.Client.Runtime.dll'

 

if you downloaded the NuGet package and extracted it to C:Tools

add-type -path C:Toolsmicrosoft.sharepointonline.csom.16.1.6906.1200libnet40-fullmicrosoft.sharepoint.client.dll
add-type -path C:Toolsmicrosoft.sharepointonline.csom.16.1.6906.1200libnet40-fullmicrosoft.sharepoint.client.Runtime.dll

 

Establishing a context:

 

if ([string]::IsNullOrEmpty($url)){$url=Read-Host "Site Url?"}
$ctx = new-object Microsoft.SharePoint.Client.ClientContext($url)
if ([string]::IsNullOrEmpty($c)) {$c=Get-Credential -Message "Please enter the site collection Administrator credentials" }
$ctx.Credentials = new-object Microsoft.SharePoint.Client.SharePointOnlineCredentials($c.UserName,$c.Password) -Verbose
$ctx.ExecuteQuery()

All you need to do now is to access the site or web, the lists inside it, the list elements, etc.

example:

$web =$ctx.Web
$ctx.load($web)
$ctx.ExecuteQuery()

Viewing all articles
Browse latest Browse all 34890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>