Forum Discussion

petervankeymeulen's avatar
petervankeymeulen
Copper Contributor
Mar 21, 2025

Update-MgUser : Cannot convert the literal '0' to the expected type 'Edm.String'.

Dear

I use the Graph API from a Power Shell script. I replaced all Azure Ad command let code in my scripts with Graph API code. I need to set the Company attribute in Azure. Users that do not have a value for company need to have "00000". Whatever I try, I always get the same error: 

 

$Organizationid =”00000”
$MgUser = Get-MgUser -Filter "mail eq '$EmailAddress'"
$body = @{CompanyName = $Organizationid } | ConvertTo-Json -Depth 1
Update-MgUser -UserId $MgUser.Id -BodyParameter $body
Update-MgUser : Cannot convert the literal '0' to the expected type 'Edm.String'.

 

$Organizationid =”00000”
$MgUser = Get-MgUser -Filter "mail eq '$EmailAddress'"
Update-MgUser -UserId $MgUser.Id - CompanyName $Organizationid
Update-MgUser : Cannot convert the literal '0' to the expected type 'Edm.String'.

 

[STRING]$Organizationid =”00000”
$MgUser = Get-MgUser -Filter "mail eq '$EmailAddress'"
Update-MgUser -UserId $MgUser.Id - CompanyName $Organizationid
Update-MgUser : Cannot convert the literal '0' to the expected type 'Edm.String'.

[STRING]$Organizationid =”00000”


$MgUser = Get-MgUser -Filter "mail eq '$EmailAddress'"
Update-MgUser -UserId $MgUser.Id - CompanyName $($Organizationid)
Update-MgUser : Cannot convert the literal '0' to the expected type 'Edm.String'.

 

Anyone an idea how to solve this?

Thanks for the feedback
Regards
Peter

2 Replies

  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    Hi petervankeymeulen,

     

    JonathanDatois correct, and you can see this in action if you run the comandlet using the -Debug parameter.

     

    Example 1

    Commandlet being run

    Update-MgBetaUser -UserId "3e8a5b03-507b-4bd6-98be-69fae0efcaf2" -CompanyName "00000" -Debug;

     

    Debug output

     

    Example 2

    Commandlet being run

    You don't have to use constructs like "$()". Just use opposing quotes to enclose the string value versus those inside of the string.

    You can see I've used single quotes to enclose the string while using double quotes inside the string, where because the single quote is the first quote PowerShell sees, it considers it to be the delimiter.

    Note: You could just as easily reverse the quotes and use "'00000'" but for reasons I wont bore you with, I've quite deliberately chosen single quotes to enclose the string in for this static value.

    Update-MgBetaUser -UserId "3e8a5b03-507b-4bd6-98be-69fae0efcaf2" -CompanyName '"00000"' -Debug;

     

    Debug output

     

    Sadly, not all commandlets produce useful output when -Debug is specified, but fortunately the Microsoft Graph commandlets do, which is great when diagnosing issues with type conversion in the body.

     

    Cheers,

    Lain

  • JonathanDato's avatar
    JonathanDato
    Copper Contributor

    Hey man, I was having the same issues with EmployeeID but I think it should be the same solution for you! I hope it helps.

    -CompanyName $("'" + $Organizationid + "'")

Resources