Mar 14 2024 07:10 AM
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
Mar 14 2024 08:17 AM - edited Mar 15 2024 03:10 AM
@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.
Mar 14 2024 08:21 AM