-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathConnect-365.ps1
718 lines (646 loc) · 24.2 KB
/
Connect-365.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
<#
.SYNOPSIS
Connect to Office 365 services via PowerShell
.DESCRIPTION
This script will prompt for your Office 365 tenant credentials and connect you to any or all Office 365 services via remote PowerShell
.INPUTS
None
.OUTPUTS
None
.NOTES
Version: 1.3.1
Author: Chris Goosen (Twitter: @chrisgoosen)
Creation Date: 23 Nov 2023
Credits: Ver >= 1.3 ExchangeMFAModule handling by Michel de Rooij - eightwone.com, @mderooij
Bugfinder extraordinaire Greig Sheridan - greiginsydney.com, @greiginsydney
Various bugfixes: Andy Helsby - github.com/Absoblogginlutely
.LINK
http://www.cgoosen.com
.EXAMPLE
.\Connect-365.ps1
#>
$ErrorActionPreference = "Stop"
$ScriptVersion = "1.3.1"
$ScriptName = "Connect365"
$ScriptDisplayName = "Connect-365"
$ScriptURL = "https://github.com/cgoosen/Connect-365/releases/"
#region XAML code
$XAML = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="Connect-365" Height="420" Width="550" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
<Grid>
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Name="Btn_Exit" Header="_Exit" />
</MenuItem>
<MenuItem Header="_Edit">
<MenuItem Command="Cut" />
<MenuItem Command="Copy" />
<MenuItem Command="Paste" />
</MenuItem>
<MenuItem Header="_Help">
<MenuItem Header="_About">
<MenuItem Name="Btn_About" Header="_Script Version $ScriptVersion"/>
</MenuItem>
<MenuItem Name="Btn_Help" Header="_Get Help" />
</MenuItem>
</Menu>
</DockPanel>
<TabControl Margin="0,20,0,0">
<TabItem Name="Tab_Connection" Header="Connection Options" TabIndex="12">
<Grid Background="White">
<StackPanel>
<StackPanel Height="32" HorizontalAlignment="Center" VerticalAlignment="Top" Width="538" Margin="0,0,0,0">
<Label Content="Microsoft 365 Remote PowerShell" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0" Height="32" FontWeight="Bold"/>
</StackPanel>
<StackPanel Height="32" HorizontalAlignment="Center" VerticalAlignment="Top" Width="538" Margin="0,0,0,0" Orientation="Horizontal">
<Label Content="Username:" HorizontalAlignment="Left" Height="32" Margin="10,0,0,0" VerticalAlignment="Center" Width="70" FontSize="11" VerticalContentAlignment="Center"/>
<TextBox Name="Field_User" HorizontalAlignment="Left" Height="22" Margin="0,0,0,0" TextWrapping="Wrap" VerticalAlignment="Center" Width="438" VerticalContentAlignment="Center" FontSize="11" BorderThickness="1" TabIndex="1"/>
</StackPanel>
<StackPanel Height="32" HorizontalAlignment="Center" VerticalAlignment="Top" Width="538" Margin="0,0,0,0" Orientation="Horizontal">
<Label Content="Password:" HorizontalAlignment="Left" Height="32" Margin="10,0,0,0" VerticalAlignment="Center" Width="70" FontSize="11" VerticalContentAlignment="Center"/>
<PasswordBox Name="Field_Pwd" HorizontalAlignment="Left" Height="22" Margin="0,0,0,0" VerticalAlignment="Center" Width="438" VerticalContentAlignment="Center" FontSize="11" BorderThickness="1" TabIndex="2"/>
</StackPanel>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Top" Width="538" Margin="0,10,0,0">
<GroupBox Header="Services:" Width="508" Margin="10,0,0,0" FontSize="11" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid Height="60" Margin="0,10,0,0">
<CheckBox Name="Box_EXO" TabIndex="3" HorizontalAlignment="Left" VerticalAlignment="Top">Exchange Online</CheckBox>
<CheckBox Name="Box_AAD" TabIndex="4" HorizontalAlignment="Center" VerticalAlignment="Top">Azure AD</CheckBox>
<CheckBox Name="Box_Com" TabIndex="5" HorizontalAlignment="Right" VerticalAlignment="Top">Compliance Center</CheckBox>
<CheckBox Name="Box_SPO" TabIndex="6" HorizontalAlignment="Left" VerticalAlignment="Center">SharePoint Online</CheckBox>
<CheckBox Name="Box_MSO" TabIndex="7" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="50,0,0,0">Azure AD MSOnline</CheckBox>
<CheckBox Name="Box_Teams" TabIndex="8" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,62,0">Teams</CheckBox>
<CheckBox Name="Box_Intune" TabIndex="9" HorizontalAlignment="Left" VerticalAlignment="Bottom">Intune</CheckBox>
</Grid>
</GroupBox>
<GroupBox Header="Options:" Width="508" Margin="10,10,0,0" FontSize="11" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid Height="50" Margin="0,10,0,0">
<CheckBox Name="Box_MFA" TabIndex="10" HorizontalAlignment="Left" VerticalAlignment="Top" IsChecked="True" IsEnabled="False">Use MFA?</CheckBox>
<CheckBox Name="Box_Clob" TabIndex="11" HorizontalAlignment="Center" VerticalAlignment="Top" IsEnabled="False" Margin="20,0,0,0">AllowClobber</CheckBox>
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Bottom" Orientation="Horizontal">
<Label Content="Admin URL:" Width="70"></Label>
<TextBox Name="Field_SPOUrl" Height="22" Width="425" Margin="0,0,0,0" TextWrapping="Wrap" IsEnabled="False" TabIndex="12"></TextBox>
</StackPanel>
</Grid>
</GroupBox>
</StackPanel>
<StackPanel Height="45" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,10,0,0">
<Button Name="Btn_Ok" Content="Ok" Width="75" Height="25" VerticalAlignment="Top" HorizontalAlignment="Center" TabIndex="13" />
<Button Name="Btn_Cancel" Content="Cancel" Width="75" Height="25" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="40,0,0,0" TabIndex="14" />
</StackPanel>
</StackPanel>
</Grid>
</TabItem>
<TabItem Name="Tab_Prereq" Header="Prerequisite Checker" TabIndex="11">
<Grid Background="White">
<StackPanel>
<StackPanel>
<Grid Margin="0,10,0,0">
<Label Content="Module" HorizontalAlignment="Left" FontSize="11" FontWeight="Bold"/>
<Label Content="Status" HorizontalAlignment="Center" FontSize="11" FontWeight="Bold"/>
</Grid>
<StackPanel>
<Label BorderBrush="Black" BorderThickness="0,0,0,1" VerticalAlignment="Top"/>
</StackPanel>
</StackPanel>
<StackPanel>
<Grid Margin="0,10,0,0">
<Label Content="Azure AD Version 2" HorizontalAlignment="Left" FontSize="11"/>
<TextBlock Name="Txt_AADStatus" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="11" />
<Button Name="Btn_AADMsg" Content="Download now.." Width="125" Height="25" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,10,0" />
</Grid>
</StackPanel>
<StackPanel>
<Grid Margin="0,10,0,0">
<Label Content="SharePoint Online" HorizontalAlignment="Left" FontSize="11"/>
<TextBlock Name="Txt_SPOStatus" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="11" />
<Button Name="Btn_SPOMsg" Content="Download now.." Width="125" Height="25" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,10,0" />
</Grid>
</StackPanel>
<StackPanel>
<Grid Margin="0,10,0,0">
<Label Content="Azure AD MSOnline" HorizontalAlignment="Left" FontSize="11"/>
<TextBlock Name="Txt_MSOStatus" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="11" />
<Button Name="Btn_MSOMsg" Content="Download now.." Width="125" Height="25" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,10,0" />
</Grid>
</StackPanel>
<Grid Margin="0,10,0,0">
<Label Content="Exchange Online" HorizontalAlignment="Left" FontSize="11"/>
<TextBlock Name="Txt_EXOStatus" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="11" />
<Button Name="Btn_EXOMsg" Content="Download now.." Width="125" Height="25" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,10,0" />
</Grid>
<StackPanel>
<Grid Margin="0,10,0,0">
<Label Content="Teams" HorizontalAlignment="Left" FontSize="11"/>
<TextBlock Name="Txt_TeamsStatus" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="11" />
<Button Name="Btn_TeamsMsg" Content="Download now.." Width="125" Height="25" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,10,0" />
</Grid>
</StackPanel>
<StackPanel>
<Grid Margin="0,10,0,0">
<Label Content="Intune (MS Graph)" HorizontalAlignment="Left" FontSize="11"/>
<TextBlock Name="Txt_IntuneStatus" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="11" />
<Button Name="Btn_IntuneMsg" Content="Download now.." Width="125" Height="25" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,10,0" />
</Grid>
</StackPanel>
</StackPanel>
</Grid>
</TabItem>
</TabControl>
</Grid>
</Window>
"@
#endregion
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAMLGui = $XAML
$Reader=(New-Object System.Xml.XmlNodeReader $XAMLGui)
$MainWindow=[Windows.Markup.XamlReader]::Load( $Reader )
$XAMLGui.SelectNodes("//*[@Name]") | ForEach-Object {Set-Variable -Name "GUI$($_.Name)" -Value $MainWindow.FindName($_.Name)}
# Functions
Function Get-ScriptVersion{
[CmdletBinding()]
param(
[Parameter()]
[string]$CurrentVersion,
[string]$ScriptName
)
$LatestVersion = Invoke-RestMethod -Method Get -Uri https://cgoosen.azure-api.net/Versions/GetVersion?Name=$ScriptName
If (!$LatestVersion -or $LatestVersion -eq "Error: Something went wrong.."){
Write-Host "Unable to perform version check, visit $ScriptURL to check if you're running the latest version" -ForegroundColor Red
}
Else {
If ($LatestVersion -gt $CurrentVersion){
Write-Host "A newer version of $ScriptDisplayName is available, visit $ScriptURL to download the latest version" -ForegroundColor Red
}
Elseif ($LatestVersion -eq $CurrentVersion){
Write-Host "You are running the latest version of $ScriptDisplayName" -ForegroundColor Green
}
}
}
Function Get-Options{
If ($GUIBox_EXO.IsChecked -eq "True") {
$Script:ConnectEXO = $true
$OptionsArray++
}
If ($GUIBox_AAD.IsChecked -eq "True") {
$Script:ConnectAAD = $true
$OptionsArray ++
}
If ($GUIBox_Com.IsChecked -eq "True") {
$Script:ConnectCom = $true
$OptionsArray++
}
If ($GUIBox_MSO.IsChecked -eq "True") {
$Script:ConnectMSO = $true
$OptionsArray++
}
If ($GUIBox_SPO.IsChecked -eq "True") {
$Script:ConnectSPO = $true
$OptionsArray++
}
If ($GUIBox_Teams.IsChecked -eq "True") {
$Script:ConnectTeams = $true
$OptionsArray++
}
If ($GUIBox_Intune.IsChecked -eq "True") {
$Script:ConnectIntune = $true
$OptionsArray++
}
If ($GUIBox_MFA.IsChecked -eq "True") {
$Script:UseMFA = $true
}
}
Function Get-UserPwd{
#Password no longer needed as modern auth workflow will prompt for it again
If (!$Username) {
$MainWindow.Close()
Close-Window "Please enter a valid UserName..`nScript failed"
}
ElseIf ($OptionsArray -eq "0") {
$MainWindow.Close()
Close-Window "Please select a valid option..`nScript failed"
}
}
Function Connect-EXO{
If (Get-ModuleInfo-EXOv3 -eq "True") {
Connect-ExchangeOnline -UserPrincipalName $UserName -ShowBanner:$false
}
ElseIf (Get-ModuleInfo-EXO -eq "True") {
$EXOSession = New-EXOPSSession -ConnectionUri https://outlook.office365.com/powershell-liveid/ -UserPrincipalName $UserName
If ($Clob) {
Import-PSSession $EXOSession -AllowClobber
}
Else {
Import-PSSession $EXOSession
}
}
}
Function Connect-AAD{
Connect-AzureAD -AccountId $UserName
}
Function Connect-Com{
$CCSession = New-EXOPSSession -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -UserPrincipalName $UserName
If ($Clob) {
Import-PSSession $CCSession -AllowClobber
}
Else {
Import-PSSession $CCSession
}
}
Function Connect-MSO{
Connect-MsolService
}
Function Connect-SPO{
Connect-SPOService -Url $GUIField_SPOUrl.text
}
Function Connect-Teams{
Connect-MicrosoftTeams -AccountId $UserName
}
Function Connect-Intune{
Connect-MSGraph
}
Function Get-ModuleInfo-AAD{
try {
Import-Module -Name AzureAD
return $true
}
catch {
return $false
}
}
Function Get-ModuleInfo-MSO{
try {
Import-Module -Name MSOnline
return $true
}
catch {
return $false
}
}
Function Get-ModuleInfo-SPO{
try {
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
return $true
}
catch {
return $false
}
}
Function Get-ModuleInfo-EXO{
try {
Import-Module ExchangeOnlineManagement
return $true
}
catch {
return $false
}
}
Function Get-ModuleInfo-EXOv3{
try {
Import-Module -Name ExchangeOnlineManagement
return $true
}
catch {
return $false
}
}
Function Get-ModuleInfo-Teams{
try {
Import-Module -Name MicrosoftTeams
return $true
}
catch {
return $false
}
}
Function Get-ModuleInfo-Intune{
try {
Import-Module -Name Microsoft.Graph.Intune
return $true
}
catch {
return $false
}
}
function Close-Window ($CloseReason) {
Write-Host "$CloseReason" -ForegroundColor Red
Exit
}
function Get-FailedMsg ($FailedReason) {
Write-Host "$FailedReason. Connection failed, please check your credentials and try again.." -ForegroundColor Red
Exit
}
function Get-PreReq-AAD{
If (Get-ModuleInfo-AAD -eq "True") {
$GUITxt_AADStatus.Text = "OK!"
$GUITxt_AADStatus.Foreground = "Green"
$GUIBtn_AADMsg.IsEnabled = $false
$GUIBtn_AADMsg.Opacity = "0"
}
else {
$GUITxt_AADStatus.Text = "Failed!"
$GUITxt_AADStatus.Foreground = "Red"
$GUIBtn_AADMsg.IsEnabled = $true
}
}
function Get-PreReq-MSO{
If (Get-ModuleInfo-MSO -eq "True") {
$GUITxt_MSOStatus.Text = "OK!"
$GUITxt_MSOStatus.Foreground = "Green"
$GUIBtn_MSOMsg.IsEnabled = $false
$GUIBtn_MSOMsg.Opacity = "0"
}
else {
$GUITxt_MSOStatus.Text = "Failed!"
$GUITxt_MSOStatus.Foreground = "Red"
$GUIBtn_MSOMsg.IsEnabled = $true
}
}
function Get-PreReq-SPO{
If (Get-ModuleInfo-SPO -eq "True") {
$GUITxt_SPOStatus.Text = "OK!"
$GUITxt_SPOStatus.Foreground = "Green"
$GUIBtn_SPOMsg.IsEnabled = $false
$GUIBtn_SPOMsg.Opacity = "0"
}
else {
$GUITxt_SPOStatus.Text = "Failed!"
$GUITxt_SPOStatus.Foreground = "Red"
$GUIBtn_SPOMsg.IsEnabled = $true
}
}
function Get-PreReq-EXO{
If (Get-ModuleInfo-EXO -eq "True" -or Get-ModuleInfo-EXOv3 -eq "True") {
$GUITxt_EXOStatus.Text = "OK!"
$GUITxt_EXOStatus.Foreground = "Green"
$GUIBtn_EXOMsg.IsEnabled = $false
$GUIBtn_EXOMsg.Opacity = "0"
}
else {
$GUITxt_EXOStatus.Text = "Failed!"
$GUITxt_EXOStatus.Foreground = "Red"
$GUIBtn_EXOMsg.IsEnabled = $true
}
}
function Get-PreReq-Teams{
If (Get-ModuleInfo-Teams -eq "True") {
$GUITxt_TeamsStatus.Text = "OK!"
$GUITxt_TeamsStatus.Foreground = "Green"
$GUIBtn_TeamsMsg.IsEnabled = $false
$GUIBtn_TeamsMsg.Opacity = "0"
}
else {
$GUITxt_TeamsStatus.Text = "Failed!"
$GUITxt_TeamsStatus.Foreground = "Red"
$GUIBtn_TeamsMsg.IsEnabled = $true
}
}
function Get-PreReq-Intune{
If (Get-ModuleInfo-Intune -eq "True") {
$GUITxt_IntuneStatus.Text = "OK!"
$GUITxt_IntuneStatus.Foreground = "Green"
$GUIBtn_IntuneMsg.IsEnabled = $false
$GUIBtn_IntuneMsg.Opacity = "0"
}
else {
$GUITxt_IntuneStatus.Text = "Failed!"
$GUITxt_IntuneStatus.Foreground = "Red"
$GUIBtn_IntuneMsg.IsEnabled = $true
}
}
function Get-PreReq{
Get-PreReq-AAD
Get-PreReq-MSO
Get-PreReq-SPO
Get-PreReq-EXO
Get-PreReq-Teams
Get-PreReq-Intune
}
function Get-OKBtn{
$Script:Username = $GUIField_User.Text
$Passwd = $GUIField_Pwd.Password
Get-Options
Get-UserPwd
If ($Passwd) {
$EncryptPwd = $Passwd | ConvertTo-SecureString -AsPlainText -Force
$Script:Credential = New-Object System.Management.Automation.PSCredential($Username,$EncryptPwd)
}
$Script:EndScript = 2
$MainWindow.Close()
}
function Get-CancelBtn{
$MainWindow.Close()
$Script:EndScript = 1
Close-Window 'Script cancelled'
}
# Event Handlers
$MainWindow.add_KeyDown({
param
(
[Parameter(Mandatory)][Object]$Sender,
[Parameter(Mandatory)][Windows.Input.KeyEventArgs]$KeyPress
)
if ($KeyPress.Key -eq "Enter"){
Get-OKBtn
}
if ($KeyPress.Key -eq "Escape"){
Get-CancelBtn
}
})
$MainWindow.add_Closing({
$Script:EndScript++
})
$GUIBtn_Cancel.add_Click({
Get-CancelBtn
})
$GUIBtn_Ok.add_Click({
Get-OKBtn
})
$GUITab_Prereq.add_Loaded({
})
$GUIBtn_AADMsg.add_Click({
try {
Start-Process -FilePath https://www.powershellgallery.com/packages/AzureAD
}
catch {
$MainWindow.Close()
Close-Window "An error occurred..`nExiting script"
}
})
$GUIBtn_MSOMsg.add_Click({
try {
Start-Process -FilePath https://www.powershellgallery.com/packages/MSOnline
}
catch {
$MainWindow.Close()
Close-Window "An error occurred..`nExiting script"
}
})
$GUIBtn_SPOMsg.add_Click({
try {
Start-Process -FilePath http://go.microsoft.com/fwlink/p/?LinkId=255251
}
catch {
$MainWindow.Close()
Close-Window "An error occurred..`nExiting script"
}
})
$GUIBtn_EXOMsg.add_Click({
try {
Start-Process -FilePath https://www.powershellgallery.com/packages/ExchangeOnlineManagement
}
catch {
$MainWindow.Close()
Close-Window "An error occurred..`nExiting script"
}
})
$GUIBtn_TeamsMsg.add_Click({
try {
Start-Process -FilePath https://www.powershellgallery.com/packages/MicrosoftTeams
}
catch {
$MainWindow.Close()
Close-Window "An error occurred..`nExiting script"
}
})
$GUIBtn_IntuneMsg.add_Click({
try {
Start-Process -FilePath https://github.com/Microsoft/Intune-PowerShell-SDK
}
catch {
$MainWindow.Close()
Close-Window "An error occurred..`nExiting script"
}
})
$GUIBox_EXO.add_Click({
$GUIBox_Clob.IsEnabled = "True"
})
$GUIBox_Com.add_Click({
$GUIBox_Clob.IsEnabled = "True"
})
$GUIBox_SPO.add_Checked({
$GUIField_SPOUrl.IsEnabled = "True"
$GUIField_SPOUrl.Text = "Enter your SharePoint Online Admin URL, e.g https://<tenant>-admin.sharepoint.com"
})
$GUIBox_SPO.add_UnChecked({
$GUIField_SPOUrl.IsEnabled = "False"
$GUIField_SPOUrl.Text = ""
})
$GUIField_SPOUrl.add_GotFocus({
$GUIField_SPOUrl.Text = ""
})
$GUIBtn_Exit.add_Click({
Get-CancelBtn
})
$GUIBtn_About.add_Click({
Start-Process -FilePath http://cgoo.se/2ogotCK
})
$GUIBtn_Help.add_Click({
Start-Process -FilePath http://cgoo.se/1srvTiS
})
# Script re-req checks
Write-Host "Starting script version $ScriptVersion..`nLooking for newer version.." -ForegroundColor Green
Get-ScriptVersion -CurrentVersion $ScriptVersion -ScriptName $ScriptName
Write-Host "Done!" -ForegroundColor Green
Write-Host "Looking for installed modules.." -ForegroundColor Green
Get-PreReq
Write-Host "Done!" -ForegroundColor Green
# Load GUI Window
$MainWindow.WindowStartupLocation = "CenterScreen"
$MainWindow.ShowDialog() | Out-Null
# Check if Window is closed
If ($EndScript -eq 1){
Close-Window 'Script cancelled'
}
# Connect to EXO if required
If ($ConnectEXO -eq "True"){
Try {
Connect-EXO
}
Catch {
Get-FailedMsg 'Exchange Online error'
}
}
# Connect to SharePoint Online if required
If ($ConnectSPO-eq "True"){
Try {
Connect-SPO
}
Catch {
Get-FailedMsg 'SharePoint Online error'
}
}
# Connect to Security & Compliance Center if required
If ($ConnectCom -eq "True"){
Try {
Start-Sleep -Seconds 2
Connect-Com
}
Catch {
Get-FailedMsg 'Security & Compliance Center error'
}
}
# Connect to AAD if required
If ($ConnectAAD -eq "True"){
Try {
Connect-AAD
}
Catch {
Get-FailedMsg 'Azure AD error'
}
}
# Connect to Teams if required
If ($ConnectTeams -eq "True"){
Try {
Connect-Teams
}
Catch {
Get-FailedMsg 'Teams error'
}
}
# Connect to Intune if required
If ($ConnectIntune -eq "True"){
Try {
Connect-Intune
}
Catch {
Get-FailedMsg 'Intune error'
}
}
# Connect to Azure AD MSOnline if required
If ($ConnectMSO -eq "True"){
Try {
Connect-MSO
}
Catch {
Get-FailedMsg 'Azure AD MSOnline error'
}
}
# Notifications/Information
Clear-Host
Write-Host "
Your username is: $UserName" -ForegroundColor Yellow -BackgroundColor Black
Write-Host "You are now connected to:" -ForegroundColor Yellow -BackgroundColor Black
If ($ConnectEXO -eq "True"){
Write-Host "-Exchange Online" -ForegroundColor Yellow -BackgroundColor Black
}
If ($ConnectAAD -eq "True"){
Write-Host "-Azure Active Directory" -ForegroundColor Yellow -BackgroundColor Black
}
If ($ConnectCom -eq "True"){
Write-Host "-Office 365 Security & Compliance Center" -ForegroundColor Yellow -BackgroundColor Black
}
If ($ConnectMSO -eq "True"){
Write-Host "-Azure AD MSOnline" -ForegroundColor Yellow -BackgroundColor Black
}
If ($ConnectSPO -eq "True"){
Write-Host "-SharePoint Online" -ForegroundColor Yellow -BackgroundColor Black
}
If ($ConnectTeams -eq "True"){
Write-Host "-Teams" -ForegroundColor Yellow -BackgroundColor Black
}
If ($ConnectIntune -eq "True"){
Write-Host "-Intune API" -ForegroundColor Yellow -BackgroundColor Black
}