-
Notifications
You must be signed in to change notification settings - Fork 3
/
Globals.ps1
58 lines (50 loc) · 1.4 KB
/
Globals.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
#--------------------------------------------
# Declare Global Variables and Functions here
#--------------------------------------------
#Sample function that provides the location of the script
function Get-ScriptDirectory
{
<#
.SYNOPSIS
Get-ScriptDirectory returns the proper location of the script.
.OUTPUTS
System.String
.NOTES
Returns the correct path within a packaged executable.
#>
[OutputType([string])]
param ()
if ($hostinvocation -ne $null)
{
Split-Path $hostinvocation.MyCommand.path
}
else
{
Split-Path $script:MyInvocation.MyCommand.Path
}
}
#Sample variable that provides the location of the script
[string]$ScriptDirectory = Get-ScriptDirectory
function Connect-O365 {
[CmdletBinding()]
param ()
process {
$Params = @{
ConfigurationName = 'Microsoft.Exchange'
ConnectionUri = 'https://ps.outlook.com/powershell/'
Credential = $Global:Credential
Authentication = 'Basic'
AllowRedirection = $true
WarningAction = 'SilentlyContinue'
Name = 'O365'
ErrorAction = 'Stop'
}
try {
$Global:o365Session = New-PSSession @Params
Import-PSSession $Global:o365Session -Prefix 'O365' -AllowClobber -DisableNameChecking -ErrorAction Stop | Out-Null
}
catch {
$Global:o365Session = $Null
}
}
}