Am I doing something wrong?

Copper Contributor

Hi all

I am clearly missing something obvious.

 

I have two CSV files.  One with a list of 'Project names' One with a list of 'partial' group names.

I need to make an AzureAD group name based on the data in each CSV.

 

So, for example, Projects.csv looks like this:

PROJECTS

Project-1

Project-2

Project-3

 

Groups.csv looks like this:

GROUPS

-Group-1

-Group-2

-Group-3

 

I'm looking to work though each and have a group created that looks like this:

SharePoint-Project-1-Group-1

SharePoint-Project-1-Group-2

etc etc

 

The code I'm currently trying to use is like this:

 

 

 

# Path to CSV files
$projectCSV = "C:\path\to\project.csv"
$groupCSV = "C:\path\to\group.csv"

# Read CSV files
$projects = Import-Csv $projectCSV
$groups = Import-Csv $groupCSV

# Loop through each combination of project and group
foreach ($project in $projects) {
    foreach ($group in $groups) {
        # Create Azure AD group
        $groupName = 'SharePoint-' + $project.ProjectName + $group.GroupName
        $groupDescription = "Group for project '$($project.ProjectName)' and SharePoint group '$($group.GroupName)'"
        
        # Create the group
        New-AzureADGroup -DisplayName $groupName -Description $groupDescription -MailEnabled $false -SecurityEnabled $true -MailNickName $groupName
    }
}

 

 

Seems the $projectName and $groupName s are empty :(

Am I being thick?

 

 

Any help would be awesome.

 

Cheers

 

 

Preston

3 Replies

@Preston_Cole Do your CSV files really look like that? I mean just one column for each file? If they do, then the problem is, that in your loop you specify properties (=column names) that don't exist in your CSV files.

For example

 

 

$project.ProjectName

 

 

would refer to the value of the row "ProjectName" in your CSV of the current object.

Thanks for the pointer! The headings were slightly wrong, I had Project.Name as a heading!

You helped me look again.

THANKS!!
Awesome! Glad to help :)