forked from directorcia/Office365
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho365-connect-sac.ps1
42 lines (33 loc) · 1.45 KB
/
o365-connect-sac.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
## CIAOPS
## Script provided as is. Use at own risk. No guarantees or warranty provided.
## Prerequisites = 1
## 1. Ensure msonline module installed or updated
## Variables
$savedcreds=$false ## false = manually enter creds, True = from file
$credpath = "c:\downloads\tenant.xml" ## local file with credentials if required
clear-host
## set-executionpolicy remotesigned
## May be required once to allow ability to runs scripts in PowerShell
## ensure that install-module msonline has been run
## ensure that update-module msonline has been run to get latest module
import-module msonline
write-host -foregroundcolor green "MSOnline module loaded"
## Get tenant login credentials
if ($savedcreds) {
## Get creds from local file
$cred =import-clixml -path $credpath
}
else {
## Get creds manually
$cred=get-credential
}
## Connect to Office 365 admin service
connect-msolservice -credential $cred
write-host -foregroundcolor green "Now connected to Office 365 Admin service"
## Connect to the Office 365 Security and Compliance Center
Write-Output "Getting the Security & Compliance Center cmdlets"
$Session = New-PSSession -ConfigurationName Microsoft.Exchange `
-ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ `
-Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $Session
write-host -foregroundcolor green "Now connected to Office 365 Security and Compliance Center"