Skip to content

Instantly share code, notes, and snippets.

@dmadelung
Last active January 26, 2018 16:35
Show Gist options
  • Save dmadelung/d1d619527cef608fd83bffb307e3c5ca to your computer and use it in GitHub Desktop.
Save dmadelung/d1d619527cef608fd83bffb307e3c5ca to your computer and use it in GitHub Desktop.
add-type -Path "C:\Users\dmadelung\SPCSOM\Microsoft.SharePoint.Client.dll"
add-type -Path "C:\Users\dmadelung\SPCSOM\Microsoft.SharePoint.Client.Runtime.dll"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext("https://domain-my.sharepoint.com/personal/drew_drewmadelung_com")
$ss = Read-Host -Prompt "Enter password" -AsSecureString
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("drew@drewmadelung.com", $ss)
$web = $ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()
$email = "haaron@drewmadelung.com"
$jsonPerson = "[{`"Key`":`"$email`",`"Description`":`"$email`",`"DisplayText`":`"$email`",`"EntityType`":`"`",`"ProviderDisplayName`":`"`",`"ProviderName`":`"`",`"IsResolved`":true,`"EntityData`":{`"Email`":`"$email`",`"AccountName`":`"$email`",`"Title`":`"$email`",`"PrincipalType`":`"UNVALIDATED_EMAIL_ADDRESS`"},`"MultipleMatches`":[]}]"
$roleValue = "role:1073741827"
$propageAcl = $false
$sendEmail = $true
$includedAnonymousLinkInEmail = $false
$groupId = 0
$docUrl = "https://domain-my.sharepoint.com/personal/drew_drewmadelung_com/Documents/CE343w.pptx"
$emailSubject = "" #doesn't matter
$emailBody = ""
$useSimplifiedRoles = $true
$result = [Microsoft.SharePoint.Client.Web]::ShareObject($web.Context,$docurl,$jsonPerson,$roleValue,$groupid,$propageAcl,$sendEmail,$includedAnonymousLinkInEmail,$emailSubject,$emailBody,$useSimplifiedRoles)
$web.Context.Load($result)
$web.Context.ExecuteQuery()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment