Skip to content

Instantly share code, notes, and snippets.

@BasantPandey
Created September 23, 2018 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BasantPandey/ac357c49302be4b08b717bee9c786284 to your computer and use it in GitHub Desktop.
Save BasantPandey/ac357c49302be4b08b717bee9c786284 to your computer and use it in GitHub Desktop.
Connect SharePoint Using Username and password
$ProgressPreference = "SilentlyContinue"
$WarningPreference = "SilentlyContinue"
#Import Modudle
Import-Module $PSScriptRoot\SharePointPnPPowerShellOnline\SharePointPnPPowerShellOnline.psd1 -ErrorAction SilentlyContinue
#Uncomment to run the same script to your local
#$env:APPSETTING_PWord="<Passowrd>"
#$env:APPSETTING_User="<userName>"
#$env:APPSETTING_TenantURL="https://sharepointfordeveloper.sharepoint.com"
#Read values from the Application Settings WebJobs
$tenantURL = ([environment]::GetEnvironmentVariable("APPSETTING_TenantURL"))
$tenantURL1 = ([environment]::GetEnvironmentVariable("APPSETTING_TenantURL"))
$User = ([environment]::GetEnvironmentVariable("APPSETTING_User"))
$PlainPassword = ([environment]::GetEnvironmentVariable("APPSETTING_PWord"))
#Create the Secure Password
$SecurePassword = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force
Write-Output $tenantURL
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$SecurePassword
#Create the Admin URL incase to connect to the Admin
$uri = [Uri]$tenantURL
$tenantUrl = $uri.Scheme + "://" + $uri.Host
$tenantAdminUrl = $tenantUrl.Replace(".sharepoint", "-admin.sharepoint")
$SiteCreationUrl = "/teams/sitecreation"
"$tenantURL1$SiteCreationUrl"
Connect-PnPOnline -Url "$tenantURL1$SiteCreationUrl" -Credentials $Credential
$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