Permalink
Find file Copy path
b5eae53 Sep 28, 2018
1 contributor

Users who have contributed to this file

201 lines (160 sloc) 7.24 KB
#All of the PowerShell for getting data from Azure Storage comes from Brian Caauwe's post http://www.avtex.com/2018/06/azure-automation-provisioning/
#This script was utilized during Ignite 2018 for a site provisioning
#There are multiple parameters that will need to be updated below
[CmdletBinding()]
Param(
[string]$sitetitle,
[string]$siteurl,
[string]$siteowner,
[string]$sitetype,
[string]$sitealias,
[string]$sitedetails
)
#create site functions
function Comm-CreateSite {
Write-Output ("Creating a Communication Site")
#create site
New-PnPSite -Type CommunicationSite -Title $sitetitle -Url $siteurl -Lcid 1033
#wait for site to be created
do {
Start-Sleep -Seconds 1
Write-Output ("Checking for site to finish creating")
Connect-PnPOnline -Url $siteurl -Credentials $cred -ErrorAction SilentlyContinue
$site = Get-PnPSite -ErrorAction SilentlyContinue
} while ($site -eq $null)
#extra pause
Write-Output ("Pausing while site is being creating")
Start-Sleep -Seconds 5
#add theme
$sitedesign = Get-PnPSiteDesign | where {$_.Title -eq "ADDSITEDESIGNTITLE"}
Invoke-PnPSiteDesign -Identity $sitedesign.Id
#add owner to group
$ownergroup = Get-PnPGroup | where {$_.Title -like "*Owners*"}
Add-PnPUserToGroup -LoginName $siteowner -Identity $ownergroup.Id
#add all company if required
if($sitedetails -like "*AllCompany*"){
Write-Output ("Adding everyone except external users to comm site")
$visitorgroup = Get-PnPGroup | where {$_.Title -like "*Visitor*"}
Add-PnPUserToGroup -LoginName "c:0-.f|rolemanager|spo-grid-all-users/GETYOUROWNGUIDHERE" -Identity $visitorgroup.Id
}
}
function Partner-CreateSite {
Write-Output ("Creating a Partner Collaboration Site")
New-PnPTenantSite -Title $sitetitle -Url $siteurl -Owner $siteowner -Lcid 1033 -Template "STS#3" -TimeZone 11 -Wait
}
function Team-CreateSite {
Write-Output ("Creating a Team Collaboration Site")
New-PnPSite -Type TeamSite -Title $sitetitle -Url $siteurl -Lcid 1033
}
function PM-CreateSite {
Write-Output ("Creating a Project Management Site")
New-PnPSite -Type TeamSite -Alias $sitealias -Title $sitetitle
#wait for site to be created
Write-Output ("Checking for site to finish creating")
do {
Start-Sleep -Seconds 1
Connect-PnPOnline -Url $siteurl -Credentials $cred -ErrorAction SilentlyContinue
$site = Get-PnPSite -ErrorAction SilentlyContinue
} while ($site -eq $null)
#extra pause
Write-Output ("Pausing while site is being creating")
Start-Sleep -Seconds 5
#add site design
Write-Output ("Adding site design")
$sitedesign = Get-PnPSiteDesign | where {$_.Title -eq "ADDSITEDESIGNTITLE"}
Invoke-PnPSiteDesign -Identity $sitedesign.Id
#add owner to SharePoint group
#This should be updated to use the *-UnifiedGroup* exchange online cmdlets to update group membership
Write-Output ("Updating SP Group owners")
$ownergroup = Get-PnPGroup | where {$_.Title -like "*Owners*"}
Add-PnPUserToGroup -LoginName $siteowner -Identity $ownergroup.Id
#apply pnp provisioning
Write-Output ("Applying PnP template")
$filename = "pmtemplate.xml"
#$logoname = "pmcolorlogo.png"
$connString = Get-AutomationVariable -Name 'StorageConnString'
$containerName = Get-AutomationVariable -Name 'StorageContainer'
Write-Output ("Connecting to Azure Storage")
$storageAccount = New-AzureStorageContext -ConnectionString $connString
Write-Output ("[[ Connected to Azure Storage")
Write-Output ("Getting file '" + $fileName + "' from Azure Blob Store")
Get-AzureStorageBlobContent -Blob $fileName -Container $containerName -Destination ("c:\temp\" + $fileName) -Context $storageAccount
Write-Output ("[[ File '" + $fileName + "' saved ]]")
Write-Output ("Applying Provisioning Template")
Apply-PnPProvisioningTemplate -Path ("c:\temp\" + $fileName)
Write-Output ("[[ Provisioning Template Applied ]]")
#add to project top nav of hub site
Connect-PnPOnline -Url "https://domain.sharepoint.com/sites/sitename" -Credentials $cred
#the parent ID is the id of the term header that we want to add this as a sub header
Add-PnPNavigationNode -Location TopNavigationBar -Title $sitetitle -Url $siteurl -Parent 2006
#set logo
#This doesn't work with an App ID :(
#$appId = Get-AutomationVariable -Name 'GroupAppId'
#$appSecret = Get-AutomationVariable -Name 'GroupAppSecret'
#Write-Output ("Connecting to MS Graph")
#Connect-PnPOnline -AppId $appId -AppSecret $appSecret -AADDomain 'domain.com'
#Write-Output ("Getting file '" + $logoname + "' from Azure Blob Store")
#Get-AzureStorageBlobContent -Blob $logoname -Container $containerName -Destination ("c:\temp\" + $logoname) -Context $storageAccount
#Write-Output ("[[ File '" + $logoname + "' saved ]]")
}
function DocRep-CreateSite {
Write-Output ("Creating a Document Repository Site")
New-PnPTenantSite -Title $sitetitle -Url $siteurl -Owner $siteowner -Lcid 1033 -Template "STS#3" -TimeZone 11 -Wait
#wait for site to be created
do {
Start-Sleep -Seconds 1
Write-Output ("Checking for site to finish creating")
Connect-PnPOnline -Url $siteurl -Credentials $cred -ErrorAction SilentlyContinue
$site = Get-PnPSite -ErrorAction SilentlyContinue
} while ($site -eq $null)
#get site design for comm sites
$sitedesign = Get-PnPSiteDesign | where {$_.Title -eq "Multicolor Theme"}
Invoke-PnPSiteDesign -Identity $sitedesign.Id
}
#set fields - These should be shifted to pull from variables
$domain = "https://domain.sharepoint.com"
$status = "Connecting"
#get creds
$cred = Get-AutomationPSCredential -Name "SharePoint Login"
try {
#connect to spo
Connect-PnPOnline "https://domain-admin.sharepoint.com" -Credentials $cred
#check connection
$context = Get-PnPContext
if($context){
Write-Output ("Connected to SharePoint Online - Checking if site exists")
$status = "Connected"
$siteurl = $domain + "/sites/" + $siteurl
#check if site exists
$site = Get-PnPTenantSite $siteurl -ErrorAction SilentlyContinue
if(!$site){
$status = "Creating site"
Write-Output ("Creating a new site for $siteurl")
if ($sitetype -eq "Communication") {
Comm-CreateSite
} elseif ($sitetype -eq "Project Management") {
PM-CreateSite
} elseif ($sitetype -eq "Document Repository") {
DocRep-CreateSite
} elseif ($sitetype -eq "Partner Collaboration") {
Partner-CreateSite
} elseif ($sitetype -eq "Team Collaboration") {
Team-CreateSite
} else {
Write-Output ("No site for the site type: $sitetype")
}
} else {
Write-Output ("$siteurl already exists")
$status = "Site already exists"
}
} else {
Write-Output ("Issue connecting to SharePoint Online")
$status = "Error connecting to SharePoint Online"
}
}
catch
{
#issue with script
$status = "Ran into an issue: $($PSItem.ToString())"
Write-Output $status
}