Last active
February 1, 2019 20:27
-
-
Save jcallaghan/f8ce5972021d85c1ef3cfb3b2a68d23b to your computer and use it in GitHub Desktop.
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
# 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