Author Posts

September 5, 2018 at 4:30 pm

#Contents of foobar1.csv = vette_ionisio@foo.org
#Entry in Azure AD = vette_ionisio_foo.org#EXT#@foosso.onmicrosoft.com

Question: How can i add the phrase "#EXT#@foosso.onmicrosoft.com" to the UPN vette_ionisio@foo.org (spreadsheet contents)

Connect-AzureAD

Import-Csv D:\Powershell_temp\foobar1.csv | ForEach-Object {
$ObjectId = (Get-AzureADUser -ObjectId '$_.Userprincipalname "#EXT#@wvusso.onmicrosoft.com"').ObjectId
}

Here is error message:

Get-AzureADUser : Error occurred while executing GetUser
Code: Request_BadRequest
Message: The request URI is not valid. Since the segment 'Microsoft.DirectoryServices.User' refers to a collection, this must be the last segment in the request URI. All intermediate
segments must refer to a single resource.
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed
At line:2 char:18

Thank you for your input

Norm

September 5, 2018 at 5:01 pm

Variables can't be put in single quotes.
You can d below.
'$_.Userprincipalname "#EXT#@wvusso.onmicrosoft.com"' will not be the one you expect.

Import-Csv D:\Powershell_temp\foobar1.csv | ForEach-Object {
$ID = $_.Userprincipalname + '#EXT#@wvusso.onmicrosoft.com'
$ObjectId = (Get-AzureADUser -ObjectId $ID).ObjectId
}

September 5, 2018 at 5:24 pm

Hello Kvprasoon;

Thank you for your response it worked!!

Norm

September 5, 2018 at 6:48 pm

Great, If you were not aware of this before, I would request you to read the documentation about quoting rules.

About Quoting Rules