Connect-O365.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
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
<#PSScriptInfo
.TITLE Connect-O365
.VERSION 1.7.9
.GUID a3515355-c4b6-4ab8-8fa4-2150bbb88c96
.AUTHOR Jos Verlinde [MSFT]
.COMPANYNAME Microsoft
.COPYRIGHT Jos Verlinde 2016
.TAGS O365 RMS 'Exchange Online' 'SharePoint Online' 'Skype for Business' 'PnP-Powershell' 'Office 365'
.LICENSEURI https://github.com/Josverl/Connect-O365/raw/master/License
.PROJECTURI https://github.com/Josverl/Connect-O365
.ICONURI https://raw.githubusercontent.com/Josverl/Connect-O365/master/Connect-O365.png
.EXTERNALMODULEDEPENDENCIES MSOnline, Microsoft.Online.SharePoint.PowerShell, AADRM
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
v1.7.9 removed import collision on Credential Parameter
v1.7.8 Add -Credential Parameter, refactored to modules
v1.7.2 Update tests for changed external dependency name SharePointPnPPowerShellOnline
V1.7.1 Minor improvements in account lookup
V1.6.9 Updated changed external dependency name SharePointPnPPowerShellOnline
V1.6.8 Add global variables $TenantName and $AdminName, consistent parameter names
V1.6.7 Correct script for CredentialManager 2.0.0.0 parameter changes
V1.6.5 Add autocompletion for saved accounts and credential manager, change default for -AAD, improve connection error checks
V1.6.3 Add progress bars
V1.6.2 Resolve multiple Aliases per parameter bug on some PS flavors,
V1.6.1 Add test for Sign-in Assistant,Add pro-active check for modules during administration.
V1.6.0 Publish to Github
v1.5.9 update install OS version match logic to use [System.Environment]::OSVersion.Version, correct DefaultParameterSetName=”Admin", Add -test option to check correct installation
V1.5.8 Seperate configuration download info from script, Retrieve Module info from github.
V1.5.7 Update to SPO shell build : 5111 1200 (March 2016)
v1.5.6 Add -close parameter and fixed parameter sets, added inline help to parameters
v1.5.5 Fix Language for MSOnline / AAD module
v1.5 Add installation of dependent modules
v1.4 Correct bug wrt compliance search, remove prior created remote powershell sessions
V1.3 Add dependend module information
V1.2 Add try-catch for SPO PNP Powershell, as that is less common
V1.1 Initial publication to scriptcenter
#>


#Requires -Module @{ModuleName="CredentialManager";ModuleVersion="2.0"}
#Requires -Module @{ModuleName='ConnectO365';ModuleVersion="0.6"}

<# #Requires -Module SharePointPNPPowershellOnline #>

<#
.Synopsis
   Connect to Office 365 and get ready to administer all services.
   Includes installation of PowerShell modules 1/4/2016
.DESCRIPTION
   Connect to Office 365 and most related services and get ready to administer all services.
   The commandlet supports saving your administrative credentials in a safe manner so that it can be used in unattended files, and allows easy recall from the command line using autocompletion of saved credentials.
   Allows Powershell administration of : O365, Azure AD , Azure RMS, Exchange Online, SharePoint Online including PNP Powershell
       
.EXAMPLE
   Connect-O365 -Account 'admin@contoso.com' -SharePoint
   #Note: intellisense
    
.EXAMPLE
   Connect-O365 -Account 'admin@contoso.com' -SPO -EXO -Skype -Compliance -AADRM
 
.EXAMPLE
   #close any previously opened PS remote sessions (Exchange , Skype , Compliance Center)
   Connect-O365 -close
 
.EXAMPLE
   #Connect to MSOnline, and store securly store the credentials
   connect-O365 -Account 'admin@contoso.com' -Persist
.EXAMPLE
   #Update the password for the admin account
   connect-O365 -Account 'admin@contoso.com' -Persist
 
.EXAMPLE
   connect-O365 -Account 'admin@contoso.com' -Persist
 
   #retrieve credentials for use in other cmdlets
   $Creds = Get-myCreds 'admin@contoso.com'
 
.EXAMPLE
   #Download and Install dependent Modules
   connect-O365 -install
    
#>


[CmdletBinding(DefaultParameterSetName=”Admin")] 
[Alias("Connect-Office365")]
[OutputType([int])]
Param
(
    # Specify the (Admin) Account to authenticate with
    # paremeter completion is addedd in Dynamic Parameter s
    [Parameter(ParameterSetName="Admin",Mandatory=$true,Position=0)]
    [ValidateNotNullOrEmpty()]
    [string]$Account,

    # Save the account credentials for later use
    [Parameter(ParameterSetName="Admin",Mandatory=$false)]
    [switch]$Persist = $false, 
        
<# valid for Admin and Close #>
    #Connect to Azure AD aka MSOnline
    [Parameter(ParameterSetName="Admin",Mandatory=$false)]
    [Parameter(ParameterSetName="Credential",Mandatory=$false)]    
    [Parameter(ParameterSetName="Close",Mandatory=$false)]
    [Alias("AzureAD")] 
    [switch]$AAD = $false, 

    #Connect to Exchange Online
    [Parameter(ParameterSetName="Admin",Mandatory=$false)]
    [Parameter(ParameterSetName="Credential",Mandatory=$false)]    
    [Parameter(ParameterSetName="Close",Mandatory=$false)]
    [Alias("EXO")] 
    [switch]$Exchange = $false, 

    #Connect to Skype Online
    [Parameter(ParameterSetName="Admin",Mandatory=$false)]
    [Parameter(ParameterSetName="Credential",Mandatory=$false)]    
    [Parameter(ParameterSetName="Close",Mandatory=$false)]
    [Alias("CSO","Lync")] 
    [switch]$Skype = $false, 
    
    #Connecto to SharePoint Online
    [Parameter(ParameterSetName="Admin",Mandatory=$false)]
    [Parameter(ParameterSetName="Credential",Mandatory=$false)]    
    [Parameter(ParameterSetName="Close",Mandatory=$false)]
    [Alias("SPO","ODFB")] 
    [switch]$SharePoint = $false, 

    #Connecto to SharePoint Online PNP
    [Parameter(ParameterSetName="Admin",Mandatory=$false)]
    [Parameter(ParameterSetName="Credential",Mandatory=$false)]    
    [Parameter(ParameterSetName="Close",Mandatory=$false)]
    [Alias("PNP")] 
    [switch]$SharePointPNP = $false, 
        
    #Load and connecto to the O365 Compliance center
    [Parameter(ParameterSetName="Admin",Mandatory=$false)]
    [Parameter(ParameterSetName="Credential",Mandatory=$false)]    
    [Parameter(ParameterSetName="Close",Mandatory=$false)]
    [Alias("UCC")] 
    [switch]$Compliance = $false,

    #Connect to Azure Rights Management
    [Parameter(ParameterSetName="Admin",Mandatory=$false)]
    [Parameter(ParameterSetName="Credential",Mandatory=$false)]    
    [Parameter(ParameterSetName="Close",Mandatory=$false)]
    [Alias("RMS","AzureRMS")] 
    [switch]$AADRM = $false,

    #All Services
    [Parameter(ParameterSetName="Admin",Mandatory=$false)]
    [Parameter(ParameterSetName="Credential",Mandatory=$false)]    
    [Parameter(ParameterSetName="Close",Mandatory=$false)]
    [switch]$All = $false,

<# parameterset Creds #>
    # Specify the (Admin) Account to authenticate with
    [Parameter(ParameterSetName="Credential",Mandatory=$true,Position=0)]
    [ValidateNotNullOrEmpty()]
    [PSCredential]$Credential,

<# parameterset Close #>
    #Close all open Connections
    [Parameter(ParameterSetName="Close",Mandatory=$false)]
    [switch]$Close = $false,


<# parameterset Install #>
    #Download and Install the supporting Modules
    [Parameter(ParameterSetName="Install",Mandatory=$true)]
    [switch]$Install,

    #Specify the Language code of the modules to download ( not applicable to all modules)
    #Sample : -Language NL
    [Parameter(ParameterSetName="Install",Mandatory=$false)]
    [ValidatePattern("[a-zA-Z]{2}")]
    [Alias("Lang")] 
    $Language = $Host.CurrentUICulture.TwoLetterISOLanguageName, # EN

    #Specify the Language-Locale code of the modules to download ( not applicable to all modules)
    #Sample : -Language NL-NL
    #Sample : -Language EN-US
    [Parameter(ParameterSetName="Install",Mandatory=$false)]
    [ValidatePattern("[a-zA-Z]{2}-[a-zA-Z]{2}")]
    [Alias("LangCountry")]
    $Culture = $Host.CurrentUICulture.Name, # EN-US

    #Specify where to download the installable MSI and EXE modules to
    [Parameter(ParameterSetName="Install",Mandatory=$false)]
    $Folder = $null, #'C:\Users\Jos\Downloads',

# [Parameter(ParameterSetName="Install",Mandatory=$false)]
# $InstallPreview = $true,

#Mixed parameterset

    [Parameter(ParameterSetName="Admin",Mandatory=$false)]
    [Parameter(ParameterSetName="Credential",Mandatory=$false)]    
    [Parameter(ParameterSetName="Test",Mandatory=$false)]
    [Parameter(ParameterSetName="Close",Mandatory=$false)]
    [switch]$PassThrough = $false,

    # Test for installed external modules
    [Parameter(ParameterSetName="Test",Mandatory=$false)]    
    [Parameter(ParameterSetName="Install",Mandatory=$false)]
    [Alias("Verify")]
    [switch]$Test = $false, 

    #Force download and re-installation of modules.
    [Parameter(ParameterSetName="Install",Mandatory=$false)]
    [switch]$Repair = $false
)

DynamicParam {
    if ($PSVersionTable.PSVersion.Major -ge 5) {
        Register-ArgumentCompleter  -ParameterName "account" -ScriptBlock { 
            # Generate and set the CompletionSet
            #Types : DynamicKeyword / Property story / ProviderItem

            #Find the credentials stored in the userprofile creds folder
            $arrSet = Get-ChildItem -Path "$env:USERPROFILE\Creds" 
            $arrSet | ForEach-Object {
                # Completion text , ListItem text, Resulttype, Tooltip
                New-Object System.Management.Automation.CompletionResult $_.BaseName, $_.BaseName, 'ProviderItem', $_.FullName
            }
            #check if the credentialmanager module is installed
            $CM = get-module credentialmanager -ListAvailable | select -Last 1
            if ($cm -ne $null -and $CM.Version -eq "2.0") {
                #Find the credentials stored in the credential manager (version 2.0
                $storedcredentials = Get-StoredCredential -Type GENERIC -AsCredentialObject -WarningAction SilentlyContinue

                #Only the onese with a specified targetname different from the username
                $credentials = $storedcredentials | where { $_.UserName -like '?*@?*' -and $_.Type -eq 'GENERIC'} | select -Property UserName, @{Name="TargetName";Expression={$($_.Targetname).Replace("LegacyGeneric:target=","")}} , Type, TargetAlias, Comment 
                $credentials = $credentials | where { $_.targetname -ne $_.Username}
                #now create the list
                $credentials| ForEach-Object {
                    # Completion text , ListItem text, Resulttype, Tooltip
                    New-Object System.Management.Automation.CompletionResult $_.TargetName, $_.TargetName, 'DynamicKeyword', $_.Username
                }

                #Now All
                $credentials = $storedcredentials | where { $_.UserName -like '?*@?*' -and $_.Type -eq 'GENERIC'} | select -Property UserName, TargetName, Type, TargetAlias, Comment 
                #now create the list
                $credentials| ForEach-Object {
                    # Completion text , ListItem text, Resulttype, Tooltip
                    if ($_.Comment -ne $null ) {$TTIP = $_.Comment } else { $TTIP = $($_.Targetname).Replace("LegacyGeneric:target=","") }
                    New-Object System.Management.Automation.CompletionResult $_.UserName, $_.Username, 'History', $TTIP
                }
            }
        }
    }
}
begin {



    # Verbose log of the input parameters
    Write-Verbose -Message 'Connect-O365 Parameters :'
    $PSBoundParameters.GetEnumerator() | ForEach-Object { Write-Verbose -Message "$($PSItem)" }

    #Parameter logic for explicit and implicit -All
    If ( $PsCmdlet.ParameterSetName -ieq "Close" ) 
    {
        if ( $all -eq $false -and  $exchange -eq $false -and $skype -eq $false -and $Compliance -eq $false  -and $SharePoint -eq $false -and $AADRM -eq $false) {
            Write-Verbose "Online Workload not specified, assume all workloads"
            $all = $true
        }
    }

    If ( $PsCmdlet.ParameterSetName -iin "Close","Admin","Credential" ) 
    {
        if ( -not ( $Exchange -or $Skype -or $Compliance -or $SharePoint -or $SharePointPNP -or $AADRM ))
            { $AAD = $true } # default to AAD Only
        if ($SharePoint -or $SharePointPNP){
            ## AAD is used to find the URLS and the tenant name for SharePoint to connect to
            $AAD = $true
        }
        if ($all) {
            $AAD = $true
            $Exchange = $true
            $Skype= $true
            $Compliance = $true
            $SharePoint= $true
            $SharePointPNP = $true
            $AADRM = $TRUE
        } 
    }
    # Start and step size for the progress baks
    $script:Prog_pct = 0 
    $script:Prog_step = 12
}

Process{ 
    import-module connecto365 -DisableNameChecking -WarningAction SilentlyContinue
    
    # Optionally close any prior sessions
    If ( $PsCmdlet.ParameterSetName -eq "Close") {
         Try {
            write-verbose "Closing open session(s) for :"
            Write-Progress "Connect-O365" -CurrentOperation "Closing" -PercentComplete $script:Prog_pct ; 
            $script:Prog_pct += $prog_step
            #Close Existing (remote Powershell Sessions)
            if ($Exchange)   { 
                Write-Progress "Connect-O365" -CurrentOperation "Closing - Exchange Online" -PercentComplete $script:Prog_pct ; 
                $script:Prog_pct += $prog_step
                write-verbose "- Exchange Online"
                Get-PSSession -Name "Exchange Online" -ea SilentlyContinue | Remove-PSSession  } 
            if ($Compliance) { 
                Write-Progress "Connect-O365" -CurrentOperation "Closing - Compliance Center" -PercentComplete $script:Prog_pct ; 
                $script:Prog_pct += $prog_step
                write-verbose "- Compliance Center"
                Get-PSSession -Name "Compliance Center"  -ea SilentlyContinue | Remove-PSSession }
            if ($Skype)      { 
                Write-Progress "Connect-O365" -CurrentOperation "Closing - Skype Online" -PercentComplete $script:Prog_pct ; 
                $script:Prog_pct += $prog_step
                write-verbose "- Skype Online"
                Get-PSSession -Name "Skype Online" -ea SilentlyContinue| Remove-PSSession }
            if ($SharePoint) { 
                if ( get-module Microsoft.Online.SharePoint.Powershell )
                {
                    Write-Progress "Connect-O365" -CurrentOperation "Closing - SharePoint Online" -PercentComplete $script:Prog_pct ; 
                    $script:Prog_pct += $prog_step
                    write-verbose "- SharePoint Online"
                    Try {Disconnect-SPOService -ErrorAction Ignore } catch{}
                    
                }
            }
            if ($SharePointPNP) { 
                if ( get-module SharepointPnPPowerShellOnline )
                {
                    #Also Disconnect PNPPowershell
                    write-verbose "- Disconnect PNP Powershell"
                    Write-Progress "Connect-O365" -CurrentOperation "Closing - SharePoint Online PnP Powershell" -PercentComplete $script:Prog_pct ; 
                    $script:Prog_pct += $prog_step
                    Try { Disconnect-SPOnline -ErrorAction Ignore } catch{}
                }
            } 
            If($AADRM) { 
                if ( get-module AADRM )
                {
                    write-verbose "- Azure RMS"
                    Write-Progress "Connect-O365" -CurrentOperation "Closing - Azure RMS" -PercentComplete $script:Prog_pct ; 
                    $script:Prog_pct += $prog_step
                    Disconnect-AadrmService 
                }
            } 
            if ($PassThrough) { # Only return value if requested
                return $True
            }
        } catch {
            if ($PassThrough) { # Only return value if requested
                return $false
            }
        }
        Finally {
            Write-Progress "Connect-O365" -Completed  
        }
    }

    If ( $PsCmdlet.ParameterSetName -eq "Admin") {
        $operation = "Retrieve stored Account Credential"
        write-verbose $Operation
        Write-Progress "Connect-O365" -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 
        #retrieve admin credentials for filestore and secure store
        $admincredentials = RetrieveCredentials -account $account -Persist:$persist

    }
    
    If ( $PsCmdlet.ParameterSetName -eq "Credential") {
        $operation = "Retrieve PSCredential"
        write-verbose $Operation
        Write-Progress "Connect-O365" -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 

        if ($Credential){
            Write-verbose "Credential has been provided"
            $admincredentials = $Credential
        } else {
            Write-verbose "Need to ask for credential"
            $admincredentials = RetrieveCredentials -account $Credential 
        }
    }
    #avoid collision with UCC module import by removing the $credential variable
    Remove-Variable Credential


    # Admin , the main part and purpose
    If ( $PsCmdlet.ParameterSetName -iin "Admin","Credential" ) {
        $operation = "Connecting to O365 Services"
        write-verbose $Operation
        Write-Progress "Connect-O365" -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 
        $script:Prog_pct += $prog_step        


        if ($admincredentials -eq $null){ 
            Write-Verbose "No stored credentials could be found"
            throw "A valid Tenant Admin Account is required." 
        } 
        ${Global:AdminName} = $admincredentials.UserName
        Write-Host -f Cyan "UserName ${Global:AdminName}"
        
        ${Global:TenantName}  = $null
        if ( $AAD) {
            $operation = "Azure AD"
            write-verbose $Operation
            Write-Progress "Connect-O365" -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 
            $script:Prog_pct += $prog_step        

            $mod = 'MSOnline'
            if ( (get-module -Name $mod -ListAvailable) -eq $null ) {
                Write-warning "Required module: $mod is not installed or cannot be located."
                Write-Host "Install the missing module using the -Install parameter." -ForegroundColor Yellow
                if ($PassThrough ) { #Only return if requested
                    return $false
                }
            }
            #Imports the installed Azure Active Directory module.
            Import-Module MSOnline -Verbose:$false 
            #Establishes Online Services connection to Office 365 Management Layer.
            try { 
                Connect-MsolService -Credential $admincredentials -ErrorAction SilentlyContinue
                #get tenant name for future use
                $Initial = Get-MsolDomain -ErrorAction SilentlyContinue | ?{ $_.IsInitial -eq $true}
                if ($Initial) {
                    ${Global:TenantName} = $Initial.Name.Split(".")[0]
                    Write-Host -f Green $operation
                } else  {
                    Write-Warning "Unable to connect to Azure AD"
                }
            } catch {
                Write-Warning "Unable to connect to Azure AD"
            }
        } else {
            #
        }

        if ($Skype ){
            $operation = "Skype Online"
            write-verbose $Operation
            Write-Progress "Connect-O365" -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 
            $script:Prog_pct += $prog_step
                
            $mod = 'SkypeOnlineConnector'
            if ( (get-module -Name $mod -ListAvailable) -eq $null ) {
                Write-warning "Required module: $mod is not installed or cannot be located. "
                Write-Host "Install the missing module using the -Install parameter; or restart PowerShell" -ForegroundColor Yellow
                if ($PassThrough ) { #Only return if requested
                    return $false
                }
            }
            #Imports the installed Skype for Business Online services module.
            Import-Module SkypeOnlineConnector -Verbose:$false  -Force 

            #Remove prior Session
            Get-PSSession -Name "Skype Online" -ea SilentlyContinue| Remove-PSSession 

            #Create a Skype for Business Powershell session using defined credential.
            Try { 
                $SkypeSession = New-CsOnlineSession -Credential $admincredentials -Verbose:$false -ErrorAction SilentlyContinue -ErrorVariable ConnectError
                if ($SkypeSession) {
                    $SkypeSession.Name="Skype Online"
                    #Imports Skype for Business session commands into your local Windows PowerShell session.
                    Import-PSSession -Session  $SkypeSession -AllowClobber -Verbose:$false | Out-Null
                    Write-Host -f Green $operation
                } else {
                    Write-Warning $ConnectError[0].Message
                }
            } catch {
                Write-Warning $ConnectError[0].Message
            }

        }


        If ($SharePoint) {
            $operation = "SharePoint Online"
            write-verbose $Operation
            Write-Progress "Connect-O365" -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 
            $script:Prog_pct += $prog_step        

            if (!$AAD) {
                Throw "AAD Connection required"
            }
            try {
                $mod = 'Microsoft.Online.Sharepoint.PowerShell'
                if ( (get-module -Name $mod -ListAvailable) -eq $null ) {
                    Write-warning "Required module: $mod is not installed or cannot be located. "
                    Write-Host "Install the missing module using the -Install parameter." -ForegroundColor Yellow
                    if ($PassThrough ) { #Only return if requested
                        return $false
                    }
                }
                #Imports SharePoint Online session commands into your local Windows PowerShell session.
                Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking -Verbose:$false
                #lookup the tenant name based on the intial domain for the tenant
                Connect-SPOService -url "https://${Global:TenantName}-admin.sharepoint.com" -Credential $admincredentials
                Write-Host -f Green $operation                         
            }
            catch {
                Write-Warning "Unable to connect to SharePoint Online."
            }
        }

        If ($SharePointPNP) {

            $operation = "SharePoint Online - PnP PowerShell"
            write-verbose $Operation
            Write-Progress "Connect-O365" -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 
            $script:Prog_pct += $prog_step        

            if (!$AAD) {
                Throw "AAD Connection required"
            } 

            try { 
                write-verbose $Operation
                $mod = 'SharepointPnPPowerShellOnline'
                if ( (get-module -Name $mod -ListAvailable) -eq $null ) {
                    Write-Warning "Required module: $mod is not installed or cannot be located. "
                    Write-Host "Install the missing module using the -Install parameter." -ForegroundColor Yellow
                    if ($PassThrough ) { #Only return if requested
                        return $false
                    }
                }
                import-Module SharepointPnPPowerShellOnline -DisableNameChecking -Verbose:$false
                Connect-SPOnline -Credential $admincredentials -url "https://${Global:TenantName}.sharepoint.com"
                Write-Host -f Green $Operation
            } catch {
                Write-Warning "Unable to connect to SharePoint Online using the PnP PowerShell module"
            }
        }

        if ($Exchange ) {
            $operation = "Exchange Online"
            write-verbose $Operation
            Write-Progress "Connect-O365" -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 
            $script:Prog_pct += $prog_step        

            #Remove prior Session
            Get-PSSession -Name "Exchange Online" -ea SilentlyContinue| Remove-PSSession 

            #Creates an Exchange Online session using defined credential.
            $ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $admincredentials -Authentication "Basic" -WarningAction Ignore -ErrorAction SilentlyContinue -ErrorVariable ConnectError
            if ($ExchangeSession) {
                $ExchangeSession.Name = "Exchange Online"
                #This imports the Office 365 session into your active Shell.
                Import-PSSession $ExchangeSession -AllowClobber -Verbose:$false -DisableNameChecking | Out-Null
                Write-Host -f Green $Operation
            } else {
                Write-Warning $ConnectError[0].ErrorDetails
            }
        }

        if ($Compliance) {
            $operation = "Unified Compliance Center"
            write-verbose $Operation
            Write-Progress "Connect-O365" -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 
            $script:Prog_pct += $prog_step        
            #Remove prior Session
            Get-PSSession -Name "Compliance Center" -ea SilentlyContinue| Remove-PSSession 
            
            $PSCompliance = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $AdminCredentials -Authentication Basic -AllowRedirection -WarningAction Ignore -ErrorAction SilentlyContinue -ErrorVariable ConnectError
            if ($PSCompliance) {
                $PSCompliance.Name = "Compliance Center"
                Import-PSSession $PSCompliance -AllowClobber -Verbose:$false -DisableNameChecking | Out-Null

                Write-Host -f Green $Operation
            } else {
                Write-Warning $ConnectError[0].ErrorDetails
            }
        }
        If ($AADRM) {
            $operation = "Azure Rights Management"
            write-verbose $Operation
            Write-Progress "Connect-O365" -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 
            $script:Prog_pct += $prog_step        
            #Azure RMS
            $mod = 'AADRM'
            if ( (get-module -Name $mod -ListAvailable) -eq $null ) {
                Write-Warning "Required module: $mod is not installed or cannot be located. "
                Write-Host "Install the missing module using the -Install parameter." -ForegroundColor Yellow
                if ($PassThrough ) { #Only return if requested
                    return $false
                }
            }
            import-module AADRM -Verbose:$false

            #There is no good way to capture errors thrown
            #it is only possible to ignore errors , but that also hides the extual error report
            Connect-AadrmService -Credential $admincredentials
            try{
                $x =  Get-Aadrm -ErrorAction SilentlyContinue
                Write-Host -f Green $Operation
            } catch { 
                #do nothing
            }             
            
        }
    }

    If ( $PsCmdlet.ParameterSetName -eq "Install") {
        Write-Host -f Yellow "Starting Installation"
    
        #always perform module test after installation
        $test = $true
        #Lookup downloads location
        if ($Folder -eq $null ) {$folder = [shell32]::GetKnownFolderPath([KnownFolder]::Downloads) }
        write-verbose "Download folder : $folder"


        Get-O365ModuleFile
        $operation = "Load the required module information from the configuration file"
        write-verbose $Operation
        Write-Progress "Install External PowerShell modules to connect to Office 365" `
            -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 

        #load the required modules from a configuration file on GitHub
        $Components = Import-DataFile -url 'https://raw.githubusercontent.com/Josverl/Connect-O365/master/RequiredModuleInfo.psd1'

        #figure out the progress rate
        $script:Prog_step = 100 / $components.AdminComponents.Count
        $script:Prog_pct = $script:Prog_step

    #>
        # (Get-Module aadrm -ListAvailable).Version
        <# use the below in order to update relevant information
        Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | sort -Property DisplayName | select PSChildName, DisplayName, Publisher, DisplayVersion
        #>

        foreach ($c  in $Components.AdminComponents) {


            $operation = "Install $($C.Name)"
            write-verbose $Operation
            Write-Progress "Install External PowerShell modules to connect to Office 365" `
                -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 
            $script:Prog_pct += $prog_step 

            if ($c.Preview -ieq "Yes" -and $InstallPreview -eq $false) {
                    write-host -f Gray "Skip Preview component : $($c.Name)"
                    continue; 
            }
            #IF OS Major Specified , and if the current OS Matches the specified OS
            if ($c.OS) { 
                if ( ($c.OS).Split(",") -notcontains [System.Environment]::OSVersion.Version.Major) { 
                    write-host -f Gray "OS mismatch, Skip component : $($c.Name)"
                    continue; 
                } 
            }

            switch ($c.Type.ToUpper() )
            {
                {$_ -in "EXE","MSI"} {
                    Write-Verbose "EXE or MSI package"
                    $AppInfo = Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\$($c.ID)" -ErrorAction SilentlyContinue
                    $Installed = $false;
                    if ($AppInfo ) { 
                        $Installed = $appInfo.Displayname -ne $null
                    }
                
                    if (-not $Installed -or $force) {
                        # Filename
                        $file = Split-Path $c.Source -Leaf
                        #path in downloads
                        $msi = join-path $folder $file
                        #remove existing item prior to Downloading
                        Remove-Item $msi -Force -ea SilentlyContinue
                        try { 
                            #download it
                            Write-Verbose "Download package"
                            Invoke-WebRequest $c.Source -OutFile $msi
                            if ( Test-Path $msi ) { 
                                $Sign = Get-AuthenticodeSignature $msi
                                if ( $Sign.Status -eq 'Valid' -and $sign.SignerCertificate.DnsNameList[0].Unicode -eq 'Microsoft Corporation' ) {
                                    if ($force) { 
                                        #de-install before re-install
                                        write-host -ForegroundColor Yellow "Removing current $($c.Type) package"
                                        Start-Process -FilePath "msiexec" -ArgumentList "/uninstall $($c.ID) " -Wait
                                    }
                                    try { 
                                        if ($c.Type -ieq "MSI" ) {
                                            Write-Verbose "Install MSI package : $msi"
                                            Start-Process -FilePath "msiexec" -ArgumentList "/package $msi /passive /promptrestart" -Wait
                                        } else {
                                            $Options = "/Passive"
                                            if ($c.Setup ) { $Options = $c.SetupOptions }
                                            Write-Verbose "Install EXE package : $msi $options"                                        
                                            Start-Process -FilePath $MSI -ArgumentList $options -Wait
                                        }

                                            $AppInfo = Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\$($c.ID)" -ErrorAction SilentlyContinue
                                            Write-Host $c.Name "Version :" $AppInfo.DisplayVersion " was installed" -f Green
                                    } catch {
                                        Write-warning "$($c.Name) could not be installed"
                                        #Open in browser
                                        if (-not [string]::IsNullOrEmpty($c.Web)){
                                            Start-Process $c.Web
                                        }
                                    } 
                                }
                            }
                        } catch {
                            Write-Warning "could not install: $($c.Name)"
                        }
                    } 
                    else { 
                        Write-Host $c.Name "Version :" $AppInfo.DisplayVersion " is already installed"
                    }
                }
                "MODULE" {
                    # Add check for PS5 / WMF 5
                    if (Get-Command install-module) { 
                        #check for installed version of this module
                        $Current  = Get-Module -Name $c.Module -ListAvailable | sort -Property Version | select -First 1
                        $Source = Find-Module -Name $c.Module -Repository $c.Source -Verbose:$false
                        if ( $Current -eq $null ) {
                            write-verbose "Preparing to install module $($c.Module)"
                            #Not yet installed , find source
                            #if not installed or newer version avaialble
                            if( $Source -and $Current -eq $null -or  ($Source.Version -GT $Current.Version) ) {
                                #install it
                                $IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") 
                                #Check Admin Perms
                                if (-not $IsAdmin) {
                                    Write-Verbose "Start PS elevated to admin to run the install"
                                    Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList "-Command Install-Module -Name $($c.Module) -Repository $($c.Source)" 

                                } else {
                                    Install-Module -InputObject $source
                                }
                                $Now = Get-Module $c.Module -ListAvailable -Verbose:$false
                                if ($now){
                                    Write-Host "Installed $($now.Name) version : $($Now.Version)"
                                }
                            } else {
                                #Could not be found
                                Write-warning  "The Module $($c.Name) Could not be located"
                                #Open in browser
                                if (-not [string]::IsNullOrEmpty($c.Web)){
                                    Start-Process $c.Web
                                }
                            } 
                        } else {
                            #version already installed
                            if ($Source.Version -gt $Current.Version -or $force ) {
                                write-verbose "Updating Module $($c.Module)"
                                if (-not $IsAdmin) {
                                    Write-Verbose "Start PS elevated to admin to run the install"
                                    Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList "-Command update-Module -Name $($c.Module)" 
                                } else {
                                    update-Module -InputObject $source -Force:$force
                                }
                            }
                            else 
                            {
                                Write-verbose "Version : $($Current.Version) of $($c.Name) is already installed"
                            }
                            $NOW  = Get-Module $c.Module -ListAvailable
                            Write-Host "Version : $($NOW.Version) of $($c.Name) was newly installed"
                                       
                        }
                    } 
                    else 
                    { 
                        #No PS5 / WMF 5
                        Write-warning  "The Module $($c.Name) cannot be installed automatically. Please install manually or install WMF 5 (preview)"
                        #Open in browser
                        if (-not [string]::IsNullOrEmpty($c.Web)){
                            Start-Process $c.Web
                        }
                    }
                }
            default { Write-Warning "Unknown component type"}
            }
        }
    }

    #test is both a parameterset as well as an option for installation
    if ($test )  {
        Write-Host -f Yellow "Starting Test"    
        $script:Prog_pct = 0
        $script:Prog_step = 100 /6

        $AllOk = $true    #Let's start Positive

        $ServiceName ='Microsoft Online Services Sign-in Assistant'

        $operation = $ServiceName
        write-verbose $Operation
        Write-Progress "Test and validate External powershell modules to connect to Office 365" `
            -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 
        $script:Prog_pct += $prog_step 

        Write-Host "Validating Service: $ServiceName" -NoNewline
        $SignInAssistant = Get-Service -Name msoidsvc
        if ( $SignInAssistant -eq $null )
        {
            Write-Host 
            Write-Warning "Service : '$ServiceName' is not installed"
            $AllOk = $false
        } else {
            if ($SignInAssistant.Status -ine "Running" ) {
                Write-Host 
                Write-Warning "Service '$ServiceName' is not running"
                Write-Host "Install the missing module using the -Install parameter." -ForegroundColor Yellow
                $AllOk = $false
            }
            else {
                Write-Host " - OK" -ForegroundColor Green
            }
        }

        #test if all Local modules are installed correctly
        foreach ($module in @( "MSonline","SkypeOnlineConnector","Microsoft.Online.Sharepoint.PowerShell","SharepointPnPPowerShellOnline","AADRM" ) ) {
            $operation = $Module
            write-verbose $Operation
            Write-Progress "Test and validate External powershell modules to connect to Office 365" `
                -CurrentOperation $Operation -PercentComplete $script:Prog_pct ; 
            $script:Prog_pct += $prog_step 

            Write-Host "Validating Module : $Module" -NoNewline
            $M = Get-Module -Name $module -ListAvailable
            if ($m -eq $null) {
                Write-Host 
                Write-warning "Module '$Module' is not installed or cannot be located."
                Write-Host "Install the missing module using the -Install parameter, or restart PowerShell." -ForegroundColor Yellow
                $AllOk = $false

            } else {
                Try {
                    Import-Module -Name $module -Force -DisableNameChecking
                    remove-module -Name $module -Force
                    Write-Host " - OK" -ForegroundColor Green
                } catch   {
                    Write-Host 
                    Write-warning "Module '$Module' could not be Imported."
                    Write-Host "Install the missing module using the -Install parameter, or restart PowerShell." -ForegroundColor Yellow
                    $AllOk = $false
                }
            }
        }
        #All test complete, and -Passthough specified, return the test result
        if ($PassThrough) {
            return $AllOk
        }
    }
}

# SIG # Begin signature block
# MIIgNAYJKoZIhvcNAQcCoIIgJTCCICECAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUCllj9n7UQFT9lptsBxWiCO/C
# doqgghtjMIIDtzCCAp+gAwIBAgIQDOfg5RfYRv6P5WD8G/AwOTANBgkqhkiG9w0B
# AQUFADBlMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD
# VQQLExB3d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVk
# IElEIFJvb3QgQ0EwH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