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: image

Steps to reproduce behavior

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

image

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

#1585

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17

Most upvoted comments

@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 UserPrincipalName property directly on it.

@KoenZomers and @thunderstorm654 I can confirm that in my case the users I have issues with have a different UPN then their email address. Do we think that is something that can/would be fixed in PnP or do I need to come up with a workaround?

Hi there’s a relatively simple workaround for now. Assuming you’ve already got an email, you can do this to get their UPN:

$pnpUser = Get-PnPUser | Where-Object Email -eq $teamOwnerEmail
$teamOwnerUPN = Get-PnPProperty -ClientObject $pnpUser -Property UserPrincipalName

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 😃

Have just encountered a similar error Resource 'USERNAME@DOMAIN.COM' does not exist or one of its queried reference-property objects are not present." when sending emails using PnP. In our scenario the user principal name in AD was different to the email address. Not sure if this helps investigation!

It sure does, because I’ve been fiddling with that. Can you tell me more? Did you have to provide the UPN or the e-mail address of the user to make it work?

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.