Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $siteUrl = $_.Url
- $siteTitle = $_.Title
- $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
- $context.Credentials = $credentials
- $context.RequestTimeOut = 5000 * 60 * 10;
- $web = $context.Web
- $site = $context.Site
- $context.Load($web)
- $context.Load($site)
- $context.ExecuteQuery()
- $NavBar = $context.Web.Navigation.TopNavigationBar
- $NavigationNode = New-Object Microsoft.SharePoint.Client.NavigationNodeCreationInformation
- $NavigationNode.Title = $ItemName
- $NavigationNode.Url = $ItemUrlPath
- $NavigationNode.AsLastNode = $true
- $context.Load($NavBar.Add($NavigationNode))
- $context.ExecuteQuery()
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- Function Get-SPOContext([string]$Url,[string]$UserName,[string]$Password)
- {
- $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
- $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
- $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
- $context.Credentials = $credentials
- return $context
- }
- Function FindNavigationNodeByTitle([Microsoft.SharePoint.Client.NavigationNodeCollection]$Nodes,[string]$Title)
- {
- $context = $Nodes.Context
- $context.Load($Nodes)
- $context.ExecuteQuery()
- $node = $Nodes | Where-Object { $_.Title -eq $Title }
- return $node
- }
- Function AddNavigationNode([Microsoft.SharePoint.Client.NavigationNodeCollection]$Nodes,[string]$Title,[string]$Url){
- $context = $Nodes.Context
- $Node = New-Object Microsoft.SharePoint.Client.NavigationNodeCreationInformation
- $Node.Title = $Title
- $Node.Url = $Url
- $Node.AsLastNode = $true
- $context.Load($Nodes.Add($Node))
- $context.ExecuteQuery()
- }
- $tenantUrl = "https://tenant.sharepoint.com/"
- $userName = "username@tenant.onmicrosoft.com"
- $password = "password"
- $Context = Get-SPOContext -Url $tenantUrl -UserName $userName -Password $password
- #$NavBar = GetTopNavBar -Context $Context
- $NavBar = $Context.Web.Navigation.TopNavigationBar
- $Context.Load($NavBar)
- $Context.ExecuteQuery()
- $parentNode = FindNavigationNodeByTitle -Nodes $NavBar -Title "Hello"
- if($parentNode) {
- $Context.Load($parentNode.Children)
- $Context.ExecuteQuery()
- AddNavigationNode -Context $Nodes $parentNode.Children -Title "Tasks" -Url "/Lists/Tasks/AllItems.aspx"
- }
- $Context.Dispose()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement