Install New-UnifiedGroup

Hi,

So I’m currently trying to make a Microsoft Team generator within my Azure function app and I’m trying to use the cmdlets “New-UnifiedGroup” in PowerShell to create an O365 group, unfortunately, I can’t find any way to install it.

Here’s my code.

New-UnifiedGroup -DisplayName $DisplayName -Alias $DisplayName -EmailAddresses $EmailAddresses -Owner $EmailAddresses -RequireSenderAuthentificationEnabled $False -Verbose

$encpassword = ConvertTo-SecureString -String $password_string -AsPlainText -Force
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist ($username, $encpassword)
connect-PnPOnline -credentials $credentials -Url $url
Import-PSSession $session
New-Team -Group (Get-UnifiedGroup $DisplayName).ExternalDirectoryObjectId -Verbose

favor

 

Where it the $Session variable set in the above code ?

Here’s my entire code :

$requestBody = Get-Content $triggerInput -Raw | ConvertFrom-Json
$GroupName = $requestBody.GroupName
Write-Output $GroupName
$url = "https://tenant.sharepoint.com"
$upn = $requestBody.upn
$alias = $requestBody.Alias
$DisplayName = $requestBody.DisplayName
$EmailAddresses = $requestBody.EmailAddresses
$username = ""
$password_string = ""
New-UnifiedGroup -DisplayName $DisplayName -Alias $DisplayName -EmailAddresses $EmailAddresses -Owner $EmailAddresses -RequireSenderAuthentificationEnabled $False -Verbose
$encpassword = ConvertTo-SecureString -String $password_string -AsPlainText -Force
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist ($username, $encpassword)
connect-PnPOnline -credentials $credentials -Url $url
New-Team -Group (Get-UnifiedGroup $DisplayName).ExternalDirectoryObjectId -Verbose

Do i need to do something with $Session ?

you need to define $session before you import it