Author Posts

September 5, 2018 at 4:30 pm

#Contents of foobar1.csv =
#Entry in Azure AD =

Question: How can i add the phrase "" to the UPN (spreadsheet contents)


Import-Csv D:\Powershell_temp\foobar1.csv | ForEach-Object {
$ObjectId = (Get-AzureADUser -ObjectId '$_.Userprincipalname ""').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


September 5, 2018 at 5:01 pm

Variables can't be put in single quotes.
You can d below.
'$_.Userprincipalname ""' will not be the one you expect.

Import-Csv D:\Powershell_temp\foobar1.csv | ForEach-Object {
$ID = $_.Userprincipalname + ''
$ObjectId = (Get-AzureADUser -ObjectId $ID).ObjectId

September 5, 2018 at 5:24 pm

Hello Kvprasoon;

Thank you for your response it worked!!


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