Mar 23 2022 12:53 PM
I am trying to assign users a customattribute in Exchange for use in a Dynamic Distribution List. We are pure Azure AD (no on-prem or Hybrid); therefore, my DDL options are limited).
I cannot get PowerShell to assign the customattribute based on the output of the get-azureaduser command. Here's what I have, and where it's failing.
This produces a list of user email addresses that I want to use in the next step. This works as expected.
$Var1 = Get-AzureADUser -all $true | Where-Object -property "Foo" -eq "Bar" | ft -hidetableheaders UserPrincipalName
I'm trying to update each user with the customattribute1. I've tried multiple variations of this procedure, each failing.
$Var1 | foreach-object {
set-mailbox -identity $_ -customattribute1 "Some_Text"
}
The set-mailbox command works as intended when executed normally (outside of the script), so I'm pretty confident the syntax is correct.
The error I keep getting is:
Cannot process argument transformation on parameter 'Identity'. Cannot convert value "Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData" to type
"Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter". Error: "Cannot convert the "Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData" value of type
"Deserialized.Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData" to type "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter"."
+ CategoryInfo : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox
+ PSComputerName : outlook.office365.com
I'm lost on the "cannot convert value ... to type ...". FWIW, my background is Bash. This would be a simple for-each loop in Bash. What am I doing wrong?
Thank you for your time.
Mar 23 2022 01:06 PM
SolutionMar 23 2022 03:23 PM - edited Mar 23 2022 03:26 PM
When I run it with "| ft -hidetableheaders UserPrincipalName" it spits out a list of email addresses, e.g,Email address removedEmail address removedWhen I remove the "ft" portion it spits out all the info for each mailbox, e.g.ObjectId DisplayName UserPrincipalName UserType-------- ----------- ----------------- --------abc123def-ab12-12ab-34cd-efghijk Patrick Star Email address removed MemberWhen I try to add the customattribute I get massive error codes for each line item. The beginning of each error code starts with:Cannot process argument transformation on parameter 'Identity'. Cannot convert value "class User {DeletionTimestamp:
EDIT: NEVERMIND! It worked. I didn't catch the $_.UserPrincipalName at first. After I replied I noticed it and tried again. It worked. Thank you very much!!!
Mar 23 2022 03:42 PM