Last active
August 29, 2015 14:05
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Credentials to connect to office 365 tenenat admin url | |
$url ="https://velegandla-admin.sharepoint.com" | |
$username="spj@Velegandla.onmicrosoft.com" | |
$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") | |
Add-Type -Path (Resolve-Path "Microsoft.Online.SharePoint.Client.Tenant.dll") | |
Write-Host "CSOM libraries loaded succeessfully" -foregroundcolor black -backgroundcolor Green | |
Write-Host "authenticate to SharePoint Online Tenant site $url and get ClientContext object" -foregroundcolor black -backgroundcolor yellow | |
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($url) | |
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) | |
$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 "authenticateed to SharePoint Online Tenant site $url and get ClientContext object succeefully" -foregroundcolor black -backgroundcolor Green | |
} | |
catch | |
{ | |
Write-Host "Not able to authenticateed to SharePoint Online $_.Exception.Message" -foregroundcolor black -backgroundcolor Red | |
return | |
} | |
# Redaing Data from configuration.xml file | |
$xmlFilePath = "$PSScriptRoot\wsp.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 | |
#Get all WSP files | |
$wspFilesFolder = $PSScriptRoot + "\Solutions" | |
$wspFiles = Get-ChildItem $wspFilesFolder | |
function Add-wspsolutions($xmlsolutions) | |
{ | |
foreach ($file in $wspFiles) { | |
if($file.Name -eq $xmlsolutions.Name) | |
{ | |
Write-Host "Adding WSP file" $xmlsolutions.Name -foregroundcolor black -backgroundcolor yellow | |
$fileBytes = [System.IO.File]::ReadAllBytes($file.FullName) | |
$fileCreateInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation | |
$fileCreateInfo.Content = $fileBytes | |
$fileCreateInfo.Url = $list.RootFolder.ServerRelativeUrl + "/" + $file.Name | |
$fileCreateInfo.Overwrite = $true | |
$file = $list.RootFolder.Files.Add($fileCreateInfo) | |
$context.Load($file) | |
try | |
{ | |
$context.ExecuteQuery() | |
Write-Host "Added WSP file "$xmlsolutions.Name" successfully" -foregroundcolor black -backgroundcolor Green | |
} | |
catch | |
{ | |
Write-Host "Error while Adding WSP file "$xmlsolutions.Name" $_.Exception.Message" -foregroundcolor black -backgroundcolor yellow | |
return | |
} | |
} | |
} | |
} | |
$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 | |
$list = $context.Web.Lists.GetByTitle('Solution Gallery') | |
$context.Load($list.RootFolder) | |
$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 | |
} | |
$_.solutions.WSP | | |
ForEach-Object { | |
Add-wspsolutions ($_) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment