Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Param(
[Parameter (Mandatory= $true)]
[String] $teamname,
[Parameter (Mandatory= $true)]
[String] $owner,
[Parameter (Mandatory= $true)]
[String] $privatepublic,
[Parameter (Mandatory= $true)]
[String] $description
)
$Cred = Get-Credential
$Session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession -Session $Session -DisableNameChecking:$true -AllowClobber:$true | Out-Null
Connect-MicrosoftTeams -Credential $Cred
# Azure AD OAuth Application Token for Graph API
# Get OAuth token for a AAD Application (returned as $token)
# Application (client) ID, tenant ID and secret
#Application (client) ID, tenant ID and secret
$clientId = "xxxxxxxxxxxxxxxxxxxxxxxx"
$tenantId = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
$clientSecret = "XXXXXXXXXXXXXXXXXXXXX"
# Contruct URI
$uri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"
# Construct Body
$body1 = @{
client_id = $clientId
scope = "https://graph.microsoft.com/.default"
client_secret = $clientSecret
grant_type = "client_credentials"
}
# Get OAuth 2.0 Token
$tokenRequest = Invoke-WebRequest -Method Post -Uri $uri -ContentType "application/x-www-form-urlencoded" -Body $body1 -UseBasicParsing
$token = ($tokenRequest.Content | ConvertFrom-Json).access_token
#Get ID of team requester and set as owner.
$uri = 'https://graph.microsoft.com/beta/users/'+"$owner"+'?$select=id'
$method = "GET"
$query = Invoke-WebRequest -Method $method -Uri $uri -ContentType "application/json" -Headers @{Authorization = "Bearer $token"} -ErrorAction Stop -UseBasicParsing
$ownerID = ($query.content | ConvertFrom-Json).id
# Specify the URI to call and method
$uri = "https://graph.microsoft.com/beta/teams"
$method = "POST"
$body = @"
{
"template@odata.bind": "https://graph.microsoft.com/beta/teamsTemplates/standard",
"displayName": "$teamname",
"description": "$description",
"channels": [
{
"displayName": "01-Management",
"isFavoriteByDefault": true,
"description": "Description"
},
{
"displayName": "02-Developement",
"isFavoriteByDefault": true,
"description": "DEscription"
},
{
"displayName": "03-Marketing",
"isFavoriteByDefault": true,
"description": "Description"
},
{
"displayName": "04-Finance",
"isFavoriteByDefault": true,
"description": "Description"
}
],
"memberSettings": {
"allowCreateUpdateChannels": true,
"allowDeleteChannels": false,
"allowAddRemoveApps": true,
"allowCreateUpdateRemoveTabs": true,
"allowCreateUpdateRemoveConnectors": true
},
"guestSettings": {
"allowCreateUpdateChannels": false,
"allowDeleteChannels": false
},
"funSettings": {
"allowGiphy": true,
"giphyContentRating": "Moderate",
"allowStickersAndMemes": true,
"allowCustomMemes": true
},
"messagingSettings": {
"allowUserEditMessages": true,
"allowUserDeleteMessages": true,
"allowOwnerDeleteMessages": true,
"allowTeamMentions": true,
"allowChannelMentions": true
},
"visibility": "$Private",
"owners@odata.bind": [
"https://graph.microsoft.com/beta/users('$ownerID')"
]
}
"@
$query = Invoke-WebRequest -Method $method -Uri $uri -ContentType "application/json" -Body $body -Headers @{Authorization = "Bearer $token"} -ErrorAction Stop -UseBasicParsing
$location = ($query.Headers).Location
$GroupID = $location.Substring(8, 36)
Start-Sleep -Seconds 60
$TeamSiteName = (Get-Team -groupid $GroupID).MailNickName
$SiteURL = "https://alexholmeset.sharepoint.com/sites/"+$TeamSiteName
$DocumentLibrary = "/shared documents"
#Channels
#Config Variables
$FolderNames= "01-Management","02-Developement","03-Marketing","04-Finance"
$RelativeURL= "$DocumentLibrary" #Relative URL of the Parent Folder
Try {
#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#sharepoint online create folder powershell
Foreach($Folder in $FolderNames){
Add-PnPFolder -Name $folder -Folder $RelativeURL -ErrorAction Stop
Write-host -f Green "New Folder '$Folder' Added!"
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
#01-Management
#Config Variables
$FolderNames= "Meetings","Presentations"
$RelativeURL= $DocumentLibrary+"/01-management" #Relative URL of the Parent Folder
Try {
#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#sharepoint online create folder powershell
Foreach($Folder in $FolderNames){
Add-PnPFolder -Name $folder -Folder $RelativeURL -ErrorAction Stop
Write-host -f Green "New Folder '$Folder' Added!"
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
#02-Developement
#Config Variables
$FolderNames= "Design","Specs","Labeling"
$RelativeURL= $DocumentLibrary+"/02-Developement" #Relative URL of the Parent Folder
Try {
#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#sharepoint online create folder powershell
Foreach($Folder in $FolderNames){
Add-PnPFolder -Name $folder -Folder $RelativeURL -ErrorAction Stop
Write-host -f Green "New Folder '$Folder' Added!"
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
#Subfolder
$FolderNames= "Sketches","Requirements"
$RelativeURL= $DocumentLibrary+"/02-Developement/Design" #Relative URL of the Parent Folder
Try {
#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#sharepoint online create folder powershell
Foreach($Folder in $FolderNames){
Add-PnPFolder -Name $folder -Folder $RelativeURL -ErrorAction Stop
Write-host -f Green "New Folder '$Folder' Added!"
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
#03-Marketing
#Config Variables
$FolderNames= "Communication Brief","Competitor Review","Consumer Insights","Product FAQ","Product Information","Product Strategy"
$RelativeURL= $DocumentLibrary+"/03-Marketing" #Relative URL of the Parent Folder
Try {
#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#sharepoint online create folder powershell
Foreach($Folder in $FolderNames){
Add-PnPFolder -Name $folder -Folder $RelativeURL -ErrorAction Stop
Write-host -f Green "New Folder '$Folder' Added!"
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
#04-Finance
#Config Variables
$FolderNames= "Budget","Presentations"
$RelativeURL= $DocumentLibrary+"/04-Finance" #Relative URL of the Parent Folder
Try {
#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#sharepoint online create folder powershell
Foreach($Folder in $FolderNames){
Add-PnPFolder -Name $folder -Folder $RelativeURL -ErrorAction Stop
Write-host -f Green "New Folder '$Folder' Added!"
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.