Skip to content

Instantly share code, notes, and snippets.

@BasantPandey
Created September 23, 2018 16:59
Show Gist options
  • Save BasantPandey/c5c16613d29c4dfd81c8996b85eb8062 to your computer and use it in GitHub Desktop.
Save BasantPandey/c5c16613d29c4dfd81c8996b85eb8062 to your computer and use it in GitHub Desktop.
Connect via App
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
@BasantPandey
Copy link
Author

Please check my youtube series to know more about it Azure WebJob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment