I am using PowerShell and MSGraphAPI to write to SharePoint. I am pulling the user principal name like this:
$AssignedTech = (Get-ADUser $ENV:UserName -Properties userPrincipalName -Server ServerName.mycompany.local | Select UserPrincipalName).UserPrincipalName
This is successfully grabbing the users email address, however when I write to a new entry, all properties are written except for this field. I know I need to somehow lookup the user’s ObjectID but I can’t figure out how to do that.
My code that is writing to SharePoint is as follows.
$params = @{
fields = @{
"Title" = "$DecomServer";
"IP_x0020_Address" = "$IP";
"Assigned_x0020_Application" = "$Application";
"Domain" = "$Domain";
"Machine_x0020_Type" = "$MachineType";
"Change_x0020_Ticket_x0020_Number" = "$ChangeControl";
"Assigned_x0020_Tech" = "$AssignedTech";
"OSVersion" = "$OS";
"DateTurnedOff" = Get-Date;
"RemoveDate" = (Get-Date).AddDays(60)
}
}
New-MgSiteListItem -SiteId $siteId -ListId $listId -BodyParameter $params
Can anyone provide some guidance on how to convert the UserprincipalName to the ObjectID needed for a Person or Group field?