-
Notifications
You must be signed in to change notification settings - Fork 106
/
AssignO365Admin.ps1
90 lines (84 loc) · 2.53 KB
/
AssignO365Admin.ps1
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<#
.NOTES
===========================================================================
Created with: VS Code
Created on: 8/10/2018 1:46 PM
Created by: Vikas Sukhija
Organization:
Filename: AssignO365Admin.ps1
===========================================================================
.DESCRIPTION
This will take Input of UPN from tesxt file and assign the o365 admin role
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $True, Position = 1)]
[ValidateSet("Helpdesk Administrator",
"Service Support Administrator",
"Billing Administrator",
"Partner Tier1 Support",
"Partner Tier2 Support",
"Directory Readers",
"Exchange Service Administrator",
"Lync Service Administrator",
"User Account Administrator",
"Directory Writers",
"Company Administrator",
"SharePoint Service Administrator",
"Device Users",
"Device Administrators",
"Device Join",
"Workplace Device Join",
"Compliance Administrator",
"Directory Synchronization Accounts",
"Device Managers",
"Application Administrator",
"Application Developer",
"Security Reader",
"Security Operator",
"Security Administrator",
"Privileged Role Administrator",
"Intune Service Administrator",
"Cloud Application Administrator",
"Customer LockBox Access Approver",
"CRM Service Administrator",
"Power BI Service Administrator",
"Guest Inviter",
"Conditional Access Administrator",
"Reports Reader",
"Message Center Reader",
"Information Protection Administrator")]
$Role,
[Parameter(Mandatory = $True, Position = 2)]
[string]$filePath = $(Read-Host "Enter file path containing UserPrincipalNames")
)
function LaunchMSOL {
import-module msonline
Write-Host "Enter MS Online Credentials" -ForegroundColor Green
Connect-MsolService
}
Function RemoveMSOL {
Write-host "Close Powershell Window - No disconnect available" -ForegroundColor yellow
}
##########################Start the script#######################
Try {
LaunchMSOL
}
catch {
$_.exception
Write-Host "exception occured loading MSOL" -ForegroundColor Yellow
break;
}
try {
$users = get-content $filePath
$users | ForEach-Object {
$user = $_
Write-host "Apply $Role to $user" -ForegroundColor green
Add-MsolRoleMember -RoleMemberEmailAddress $user -RoleName $Role
}
}
catch {
$_.exception
Write-Host "exception occured applring o365 role" -ForegroundColor Yellow
}
######################################################################