forked from microsoft/AcademicContent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEduPortalAzureBulkCreate.psm1
More file actions
69 lines (57 loc) · 2.29 KB
/
EduPortalAzureBulkCreate.psm1
File metadata and controls
69 lines (57 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Script: Bulk Create Users, Resource Groups and Assign RBAC Permissions - Proof of Concept
#
# NOTE: Script does not have any error handling etc you need to ensure the CSV Files
# contain the correct headers and you enter the correct path when running the commands in powershell window.
###########################################
#Import Azure Modules into Powershell
Import-Module azure
Import-Module msonline
#This function prompts the user for a username and password of the Azure Main Account Owner
function Set-Credentials {
$Global:Cred = Get-Credential
}
#This function creates new users
#If you already have users existing in AAD or users have existing accounts do not run this
function New-Users {
param
(
[Parameter(Mandatory=$true, HelpMessage='Data Input')]
[ValidateNotNull()]
[string] $UserDataPath
)
$InputCsv = Import-Csv -Path $UserDataPath
Connect-MsolService -Credential $cred
foreach ($row in $inputCsv){
New-MsolUser -UserPrincipalName $row.UserPrincipalName -DisplayName $row.DisplayName -FirstName $row.FirstName -LastName $row.LastName -Password $row.Password -ForceChangePassword $false
}
}
#This function add new Resources Groups
function New-ResourceGroups {
param
(
[Parameter(Mandatory=$true, HelpMessage='Data Input')]
[ValidateNotNull()]
[string] $ResourceGroupsPath
)
$InputCsv = Import-Csv -Path $ResourceGroupsPath
Login-AzureRmAccount -Credential $cred
foreach ($row in $InputCsv){
New-AzureRmResourceGroup -Name $row.ResourceGroupName -Location $row.Location
Write-Host "$($row.ResourceGroupName) was created successfully"
}
}
#This function uses Role Based Access Control to assign the users to resource groups
function Set-RBACPermissions {
param
(
[Parameter(Mandatory=$true, HelpMessage='Data Input')]
[ValidateNotNull()]
[string] $RBACPermissions
)
$InputCsv = Import-Csv -Path $RBACPermissions
Login-AzureRmAccount -Credential $cred
foreach ($row in $InputCsv){
New-AzureRmRoleAssignment -SignInName $row.UserPrincipalName -ResourceGroupName $row.ResourceGroupName -RoleDefinitionName "Contributor"
Write-Host "$($row.UserPrincipalName) was successfully added into the Contributor Role for $($row.ResourceGroupName)"
}
}