|
#Credentials to connect to office 365 site collection url |
|
$username="[email protected]" |
|
$password="yourpassword" |
|
$Password = $password |ConvertTo-SecureString -AsPlainText -force |
|
|
|
Write-Host "Load CSOM libraries" -foregroundcolor black -backgroundcolor yellow |
|
Set-Location $PSScriptRoot |
|
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll") |
|
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll") |
|
|
|
Write-Host "CSOM libraries loaded successfully" -foregroundcolor black -backgroundcolor Green |
|
|
|
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) |
|
|
|
function Add-MenuNavigation($xmlNavs) |
|
{ |
|
$Nodes = $Context.Web.Navigation.TopNavigationBar |
|
$NavigationNode = New-Object Microsoft.SharePoint.Client.NavigationNodeCreationInformation |
|
$NavigationNode.Title = $xmlNavs.Title |
|
$NavigationNode.Url = $xmlNavs.Url |
|
$NavigationNode.AsLastNode = $true |
|
$Context.Load($Nodes.Add($NavigationNode)) |
|
try |
|
{ |
|
$Context.ExecuteQuery() |
|
Write-Host "Adding" $xmlNavs.Title "to Global Navigation Completed" -foregroundcolor black -backgroundcolor green |
|
} |
|
catch |
|
{ |
|
Write-Host Error Adding $xmlNavs.Title to Global Navigation $_.Exception.Message -foregroundcolor black -backgroundcolor Red |
|
} |
|
} |
|
|
|
# Redaing Data from configuration.xml file |
|
$xmlFilePath = "$PSScriptRoot\Navigation.xml" |
|
Write-Host "Load solutions xml file" -foregroundcolor black -backgroundcolor yellow |
|
[xml]$xmlContent = (Get-Content $xmlFilePath) |
|
if (-not $xmlContent) |
|
{ |
|
Write-Host "Xml was not loaded successfully." -foregroundcolor black -BackgroundColor Red |
|
return |
|
} |
|
Write-Host "Solutions xml file loaded successfully" -foregroundcolor black -BackgroundColor Green |
|
|
|
$xmlContent.sites.site| |
|
ForEach-Object { |
|
Write-Host "authenticate to SharePoint Online site collection" $xmlContent.sites.site.Url " and get ClientContext object" -foregroundcolor black -backgroundcolor yellow |
|
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($_.Url) |
|
$Context.Credentials = $credentials |
|
$context.RequestTimeOut = 5000 * 60 * 10; |
|
$web = $context.Web |
|
$site = $context.Site |
|
$context.Load($web) |
|
$context.Load($site) |
|
try |
|
{ |
|
$context.ExecuteQuery() |
|
Write-Host "authenticate to SharePoint Online site collection" $xmlContent.sites.site.Url "and get ClientContext object" -foregroundcolor black -backgroundcolor Green |
|
} |
|
catch |
|
{ |
|
Write-Host "Not able to authenticate to SharePoint Online site collection" $xmlContent.sites.site.Url "$_.Exception.Message" -foregroundcolor black -backgroundcolor Red |
|
return |
|
} |
|
#Add Menu to Global Navigation |
|
$_.globalnav.nav | |
|
ForEach-Object { |
|
Write-Host "Adding" $_.Title "to Global Navigation Starting..." -foregroundcolor black -backgroundcolor yellow |
|
Add-MenuNavigation ($_) |
|
} |
|
} |
|
|
|
|