Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
- [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
- Function Get-SPOCredentials([string]$UserName,[string]$Password)
- {
- if([string]::IsNullOrEmpty($Password)) {
- $SecurePassword = Read-Host -Prompt "Enter the password" -AsSecureString
- }
- else {
- $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
- }
- return New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
- }
- Function Configure-ListView([Microsoft.SharePoint.Client.ClientContext]$Context, [string]$ListTitle,[string]$ViewTitle)
- {
- $list = $Context.Web.Lists.GetByTitle($ListTitle)
- $view = $list.Views.GetByTitle($ViewTitle)
- $view.JSLink = "~sitecollection/SiteAssets/Tasks.js"
- $view.Update()
- $Context.Load($view)
- $Context.ExecuteQuery()
- }
- $UserName = "username@contoso.onmicrosoft.com"
- $Password = Read-Host -Prompt "Enter the password"
- $WebUrl = "https://contoso.sharepoint.com"
- $Context = New-Object Microsoft.SharePoint.Client.ClientContext($WebUrl)
- $Context.Credentials = Get-SPOCredentials -UserName $UserName -Password $Password
- Configure-ListView -Context $Context -ListTitle "Tasks" -ViewTitle "All Tasks"
- $Context.Dispose()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement