Import-Module Microsoft.Graph.Authentication<\/p>\n
Import-Module Microsoft.Graph.Identity.DirectoryManagement<\/p>\n
Connect-MgGraph -Scopes “Directory.AccessAsUser.All”<\/p>\n
Connect-AzureAD<\/p>\n
Select-MgProfile Beta<\/p>\n
#Install-Module<\/span> Microsoft.Graph<\/p>\n #Install-PackageProvider<\/span> -Name NuGet -Force<\/p>\n [array]$Devices=$null<\/p>\n $Dev=Import-Csv -Path C:\\Temp\\list.csv #CSV<\/span> path<\/p>\n $Devices1=$Dev.DeviceId<\/p>\n ForEach ($ids in $Devices1) {<\/p>\n [array]$Devices+=Get-MgDevice -Filter “DeviceId eq ‘$($ids)’” -All<\/p>\n }<\/p>\n ForEach ($Device in $Devices) {<\/p>\n If ($Device.PhysicalIds.count -gt 0) {<\/p>\n Foreach ($X in $Device.PhysicalIds) {<\/p>\n If ($X.SubString(0,10) -eq “[USER-GID]”) { $UserGuid = $X } }<\/p>\n $UserId = $UserGuid.substring(11,36)<\/p>\n If ($UserId) {<\/p>\n [array]$User = Get-MgUser -UserId $UserId -ErrorAction SilentlyContinue }<\/p>\n If ($User) {<\/p>\n Write-Host (“Device {0} owned by {1}” -f $Device.DisplayName, $User.DisplayName)<\/p>\n $Attributes = @{<\/p>\n “extensionAttributes” = @{<\/p>\n “extensionAttribute13” = $User.extensionAttribute13 }<\/p>\n } | ConvertTo-Json<\/p>\n Update-MgDevice -DeviceId $Device.Id -BodyParameter $Attributes<\/p>\n }<\/p>\n Else { Write-Host (“Device {0} owned by unknown user {1}” -f $Device.DisplayName, $UserId ) }<\/p>\n }<\/p>\n }<\/p>\n Disconnect-MgGraph<\/p>\n #device<\/span> ID and user pulled from .csv is correct but just not able to pull extensionAttribute as defined in the script . but if i change $User.extensionAttribute13 to “some value” it shows up in azure portal user devices, why am i not able to pull extension attribute from the user ?<\/p>","upvoteCount":5,"answerCount":4,"datePublished":"2022-12-07T12:34:24.000Z","author":{"@type":"Person","name":"akashgowda","url":"https://community.spiceworks.com/u/akashgowda"},"suggestedAnswer":[{"@type":"Answer","text":" Import-Module Microsoft.Graph.Authentication<\/p>\n Import-Module Microsoft.Graph.Identity.DirectoryManagement<\/p>\n Connect-MgGraph -Scopes “Directory.AccessAsUser.All”<\/p>\n Connect-AzureAD<\/p>\n Select-MgProfile Beta<\/p>\n #Install-Module<\/span> Microsoft.Graph<\/p>\n #Install-PackageProvider<\/span> -Name NuGet -Force<\/p>\n [array]$Devices=$null<\/p>\n $Dev=Import-Csv -Path C:\\Temp\\list.csv #CSV<\/span> path<\/p>\n $Devices1=$Dev.DeviceId<\/p>\n ForEach ($ids in $Devices1) {<\/p>\n [array]$Devices+=Get-MgDevice -Filter “DeviceId eq ‘$($ids)’” -All<\/p>\n }<\/p>\n ForEach ($Device in $Devices) {<\/p>\n If ($Device.PhysicalIds.count -gt 0) {<\/p>\n Foreach ($X in $Device.PhysicalIds) {<\/p>\n If ($X.SubString(0,10) -eq “[USER-GID]”) { $UserGuid = $X } }<\/p>\n $UserId = $UserGuid.substring(11,36)<\/p>\n If ($UserId) {<\/p>\n [array]$User = Get-MgUser -UserId $UserId -ErrorAction SilentlyContinue }<\/p>\n If ($User) {<\/p>\n Write-Host (“Device {0} owned by {1}” -f $Device.DisplayName, $User.DisplayName)<\/p>\n $Attributes = @{<\/p>\n “extensionAttributes” = @{<\/p>\n “extensionAttribute13” = $User.extensionAttribute13 }<\/p>\n } | ConvertTo-Json<\/p>\n Update-MgDevice -DeviceId $Device.Id -BodyParameter $Attributes<\/p>\n }<\/p>\n Else { Write-Host (“Device {0} owned by unknown user {1}” -f $Device.DisplayName, $UserId ) }<\/p>\n }<\/p>\n }<\/p>\n Disconnect-MgGraph<\/p>\n #device<\/span> ID and user pulled from .csv is correct but just not able to pull extensionAttribute as defined in the script . but if i change $User.extensionAttribute13 to “some value” it shows up in azure portal user devices, why am i not able to pull extension attribute from the user ?<\/p>","upvoteCount":5,"datePublished":"2022-12-07T12:34:24.000Z","url":"https://community.spiceworks.com/t/review-the-below-powershell-script/941862/1","author":{"@type":"Person","name":"akashgowda","url":"https://community.spiceworks.com/u/akashgowda"}},{"@type":"Answer","text":" There is a dedicated sdk cmdlet for extensions:
\nGet-MgUserExtension<\/strong><\/p>\n