Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Expand array properties and add single quote

I’m working with Azure AD and I have imported a CSV file with some group name in it and I want to add single quote to the name properties of these group to query Azure AD but I can’t seem to find any answer to my problem.

myfile.csv content:

name
Group Mémos - 1
Group Mémos - 2

I then need to add single quote to the item for when I query Azure AD

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$group = import-csv c:\temp\myfile.csv

foraech ($item in $group)
{
Get-AzureADGroup -Filter "DisplayName eq $("'$item.name'")" | select ObjectId
}

My problem is the content of $item is this:
‘@{Name=Group Mémos – 1}.name’

but what I need is this:
‘Group Mémos – 1’

How can I expand the name properties and add single quote to it?

I made a workaround by inserting the name property into another variable but I’m sure there is a way to do it that I don’t understand…

$item2 = $item.Name
Get-AzureADGroup -Filter "DisplayName eq $("'$item2'")" | select ObjectId

>Solution :

You have misplaced the $( ) subexpression operator:

$group = Import-Csv c:\temp\myfile.csv
foreach ($item in $group) {
    Get-AzureADGroup -Filter "DisplayName eq '$($item.name)'" | Select-Object ObjectId
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading