Install the module
Install-Module -Name Microsoft.Online.SharePoint.PowerShell
$loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$siteUrl = "https://tenant.sharepoint.com"
$username = read-host "type username" #example admin@tenant.onmicrosoft.com
$password = read-host "type password" -AsSecureString
#========================= Client context
===============================
$spocred= New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username,$password )
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$ctx.Credentials
= $spocred
$web = $ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()
Write-Host " Current web title is '$($web.Title)' "
No comments:
Post a Comment