I’m trying to create a Team, add channels and then create some folders using Powershell. I have placed the code below (i have commented out the adding of users as that is producing another issue at the moment).
#Setup named parameters
param ($TeamName, $TeamDescription, $headteacheremail, $hrcontactemail)
#Sign in to Microsoft Teams with mfa.
Connect-MicrosoftTeams -AccountId user@domain.com
Connect-ExchangeOnline -UserPrincipalName user@domain.com
$team = New-Team -MailNickname $TeamName -displayname $TeamName -Visibility "private"
Write-Host "Team Created: $TeamName"
Write-Host "Team GUID: $team.GroupID"
New-TeamChannel -GroupId $team.GroupId -DisplayName "2021 - 2022 Academic Year"
New-TeamChannel -GroupId $team.GroupId -DisplayName "Induction"
New-TeamChannel -GroupId $team.GroupId -DisplayName "Probation (Support Staff Only)"
New-TeamChannel -GroupId $team.GroupId -DisplayName "Employee Documents" -MembershipType "private"
Write-Host "Channels Created"
#Add the headteacher to the team as a owner
Add-TeamUser -GroupId $team.GroupId -Role Owner -User $headteacheremail
#Add the hr contact to the team as a owner
Add-TeamUser -GroupId $team.GroupId -Role Owner -User $hrcontactemail
Write-Host "Users added to channels"
Write-Host "Sleeping for 10 seconds"
#Give time for MS servers to create the team and channels before trying to interact with them. 10 seconds
Start-Sleep -s 10
#Add-TeamChannelUser -GroupId $team.GroupId -DisplayName "Employee Documents" -User $headteacheremail
#Add-TeamChannelUser -GroupId $team.GroupId -DisplayName "Employee Documents" -User $hrcontactemail
#Write-Host "Users added to channels"
$SiteURL = Get-UnifiedGroup -Identity $TeamName | Select -ExpandProperty SharePointSiteURL
Connect-PnPOnline -Url $SiteURL -UseWebLogin
Add-PnPFolder -Name "Bench marking documents" -Folder "Shared Documents/2021 - 2022 Academic Year"
Add-PnPFolder -Name "Career Development Plan - current" -Folder "Shared Documents/2021 - 2022 Academic Year"
Add-PnPFolder -Name "Flick Training Certificates" -Folder "Shared Documents/2021 - 2022 Academic Year"
Add-PnPFolder -Name "Professional Growth Plan - current" -Folder "Shared Documents/2021 - 2022 Academic Year"
Add-PnPFolder -Name "Flick Induction Training Certificate" -Folder "Shared Documents/Induction"
Add-PnPFolder -Name "Induction Policies" -Folder "Shared Documents/Induction"
Add-PnPFolder -Name "3 Month Review" -Folder "Shared Documents/Induction"
Add-PnPFolder -Name "6 Month Review" -Folder "Shared Documents/Induction"
The Team is created, channels and users added but when it comes to adding the Folders i get the following error.
Connect-PnPOnline : Cannot bind argument to parameter 'Url' because it is null.
If i run the command on its own with a Team name, it does return the sharepoint URL ok.
I’m not sure what is going on here.