pass a get-Azureaduser property to set-Azureaduser as a string

Viewed 94

I need to update the AzureADuser property companyname with the Physicaldeliveryofficename value. When I use: Get-AzureADUser -ObjectId TEst_USer@foo.com | Set-AzureADUser -userprincipalname $_.userpricipalname -CompanyName $_.Physicaldeliveryofficename

the companyname property is not updated. I think I'm missing the formatting for the $_.propertyname value to convert to a string for the -companyname property.

1 Answers

You would need to use ForEach-Object if you want to reference $_.PhysicalDeliveryOfficeName from pipeline. This example should add clarity to your code:

$azUser = Get-AzureADUser -ObjectId TEst_USer@foo.com
Set-AzureADUser $azUser -CompanyName $azUser.PhysicalDeliveryOfficeName

Alternatively, if you want to do it on one pipeline, using -PipelineVariable may work:

Get-AzureADUser -ObjectId TEst_USer@foo.com -PipelineVariable azUser |
Set-AzureADUser -CompanyName $azUser.PhysicalDeliveryOfficeName
Related