Skip to content

Instantly share code, notes, and snippets.

@jcallaghan
Last active February 1, 2019 20:27
Show Gist options
  • Save jcallaghan/f8ce5972021d85c1ef3cfb3b2a68d23b to your computer and use it in GitHub Desktop.
Save jcallaghan/f8ce5972021d85c1ef3cfb3b2a68d23b to your computer and use it in GitHub Desktop.
# Variables
$tenant = "tenant"
$adminUrl = "https://" + $tenant + "-admin.sharepoint.com"
$baseUrl = "https://" + $tenant + ".sharepoint.com"
$registerUrl = $baseUrl + "/sites/sitealias"
$registerListName = "Site Register"
$path = "C:\path\LegacyDataSites.csv"
$csv = Import-csv -path $path
# Pnp Connect (use web login needed for MFA)
Connect-PnPOnline -Url $adminUrl -UseWebLogin
# Create S Drive Hub site
$sdriveHub = $baseUrl + "/sites/sdrive"
# Create base hub site
New-PnPSite -Type CommunicationSite -Title "S Drive" -Url $sdrive -SiteDesign Blank
# Promote the hub as a hub
Connect-SPOService -Url $adminUrl
Register-SPOHubSite -Site $sdrive -Principals $null
# Connect to SPOService for tasks such as hub association
Connect-SPOService -Url $adminUrl
# Create legacy data sites from the CSV file
Connect-PnPOnline -Url $adminUrl -UseWebLogin
# Loop through each site in the CSV file
$csv | Foreach-Object {
# Data from CSV
$siteTitle = $_.SiteTitle
$alias = $_.SiteUrl
$siteurl = $baseUrl + "/sites/" + $alias
# Info line
write-host "Creating site $siteurl..." -nonewline
# Create new team site without a group
New-PnPTenantSite -Title $siteTitle -Url $siteUrl -Owner "0james.callaghan@tenant.onmicrosoft.com" -Template "STS#3" -TimeZone 2 -Wait
# Connect to the new site
Connect-PnPOnline -Url $siteurl -UseWebLogin
# Add site collection admins
Add-PnPSiteCollectionAdmin -Owners "james.callaghan@tenant.onmicrosoft.com"
# Add visitors
$group = Get-PnPGroup | Where-Object {$_.Title -like "* Visitors"}
Add-PnPUserToGroup -LoginName "O365-Data-Visitor-Group@tenant.onmicrosoft.com" -Identity $group
# Associate the site with the hub site
Add-SPOHubSiteAssociation -Site $siteurl -HubSite $sdriveHub
<#
# Add logo file to site assets
# Additional config
Set-PnPSite -CommentsOnSitePagesDisabled Disabled -LocaleId 2057 -LogoFilePath "" -Sharing Disabled
#>
# Add site to the FCO Hub site register
Connect-PnPOnline -Url $registerUrl -UseWebLogin
Add-PnPListItem -List $registerListName `
-Values @{`
"Title" = $siteTitle;`
"CloudURL" = $siteurl + ", " + $siteTitle; `
"SiteType" = "SharePoint Team Site / Office 365 Group / Microsoft Team" `
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment