Created
September 23, 2018 16:59
-
-
Save BasantPandey/c5c16613d29c4dfd81c8996b85eb8062 to your computer and use it in GitHub Desktop.
Connect via App
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
function Connect([string]$Url) { | |
if ($Url -eq $Global:lastContextUrl) { | |
return | |
} | |
if ($appId -ne $null -and $appSecret -ne $null) { | |
Connect-PnPOnline -Url $Url -AppId $appId -AppSecret $appSecret | |
} | |
else { | |
Connect-PnPOnline -Url $Url | |
} | |
$Global:lastContextUrl = $Url | |
} | |
$ProgressPreference = "SilentlyContinue" | |
$WarningPreference = "SilentlyContinue" | |
Import-Module $PSScriptRoot\SharePointPnPPowerShellOnline\SharePointPnPPowerShellOnline.psd1 -ErrorAction SilentlyContinue | |
$tenantURL = ([environment]::GetEnvironmentVariable("APPSETTING_TenantURL")) | |
$tenantURL1 = ([environment]::GetEnvironmentVariable("APPSETTING_TenantURL")) | |
$appId = ([environment]::GetEnvironmentVariable("APPSETTING_AppId")) | |
$appSecret = ([environment]::GetEnvironmentVariable("APPSETTING_AppSecret")) | |
#Uncommnet it to run local | |
#$env:APPSETTING_TenantURL="https://O365.sharepoint.com" | |
#$env:APPSETTING_AppId="XXXX" | |
#$env:APPSETTING_AppSecret="XXXXXXX" | |
$uri = [Uri]$tenantURL | |
$tenantUrl = $uri.Scheme + "://" + $uri.Host | |
$tenantAdminUrl = $tenantUrl.Replace(".sharepoint", "-admin.sharepoint") | |
$SiteCreationURL = "/teams/sitecreation" | |
Connect -Url "$tenantURL1$SiteCreationURL" | |
$site = Get-PnPSite | |
$site.Context.Load($site.RootWeb) | |
$site.Context.ExecuteQuery() | |
$Title ='Site Title: ' + $site.RootWeb.Title | |
Write-Output $Title | |
Disconnect-PnPOnline |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please check my youtube series to know more about it Azure WebJob