powershell: [BUG] New-PnPTeamsTeam: Failed to find users with user principal name
Reporting an Issue or Missing Feature
This is a bug
Expected behavior
New-PnPTeamsTeam with -Members -and/or -Owner should not throw errors
Actual behavior
New-PnPTeamsTeam throws an error below when calling -Owners
New-PnPTeamsTeam: Failed to find users with user principal name
However, the team get created no problem:

Steps to reproduce behavior
'TeamName' | %{ New-PnPTeamsTeam -DisplayName $_ -MailNickName $_ -Owners @veeam.com }

What is the version of the Cmdlet module you are running?
Name : PnP.PowerShell
Version : 1.9.47
Which operating system/environment are you running PnP PowerShell on?
- Windows
- Linux
- MacOS
- Azure Cloud Shell
- Azure Functions
- Other : please specify
Reference
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17
@thunderstorm654 I think the logic you gave only works if the user is in the web you are currently connected to? I am going to implement the following which I think works regardless of what connection you have.
$user = Get-PnpAzureADUser -Filter "mail eq '$email'"That object has a
UserPrincipalNameproperty directly on it.Hi there’s a relatively simple workaround for now. Assuming you’ve already got an email, you can do this to get their UPN:
Then just pass that in as the owners of the group/Team, and still works with a collection e.g. of multiple UPNs for multiple owners. There may be some shortcut to getting more properties in the first line but the above works 😃
Yes, I discovered it wasn’t actually sending emails but group owner/membership changes throwing the error. It appears that using UPN rather than email addresses will work in this scenario when a user’s UPN doesn’t match their email in AD. Specifically this was with the ‘Add-PnPMicrosoft365GroupOwner’ cmdlet but I would guess it’ll be the same with anything touching Team/Group owners and members! It’s generally not recommended as far as I understand it to have different UPN vs email, so I hadn’t seen this error before today!
You should be able to replicate the error by modifying a user in AD and changing their UPN, that’s how I replicated in our dev environment.