I'm trying to pass in a list of user and there roles so that I can assign roles to users using powershell. I want a json file to contain this information and have the following:
[
{
"name":"User1",
"roles":[
"System Administrator",
"System User"
]
},
{
"name":"User2",
"roles":[
"System User"
]
}
]
I ran the following Powershell:
$json = Get-Content -Raw -Path C:\temp\ExampleJsonArray.json | ConvertFrom-Json
This gives me:
name roles
---- -----
User1 {System Administrator, System User}
User2 {System User}
My question is - how do I then pass these values into a function that will loop through each user and loop through each role for the user so I can run the cmdlet that allows me to assign each role to a user one at a time?
add-RoleToUser $user $role
Above is just a basic example. I'm expecting many more users and roles so though a json file would be the easiest way to manager and automate this task.