From e0a0cbe2fe69284d2c8fc185825ecdb81fa44874 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 10 Jul 2019 19:43:58 -0400 Subject: [PATCH 1/8] COmplete revamp of authentication flow --- .../MSFT_O365User/MSFT_O365User.psm1 | 6 +- .../MSFT_ODSettings/MSFT_ODSettings.psm1 | 8 +- .../MSFT_SPOAccessControlSettings.psm1 | 13 ++- .../DSCResources/MSFT_SPOApp/MSFT_SPOApp.psm1 | 8 +- .../MSFT_SPOHubSite/MSFT_SPOHubSite.psm1 | 16 ++- .../MSFT_SPOSearchManagedProperty.psm1 | 9 +- .../MSFT_SPOSearchResultSource.psm1 | 9 +- .../MSFT_SPOSharingSettings.psm1 | 11 +- .../MSFT_SPOSite/MSFT_SPOSite.psm1 | 16 +-- .../MSFT_SPOSiteDesign.psm1 | 10 +- .../MSFT_SPOSiteDesignRights.psm1 | 9 +- .../MSFT_SPOStorageEntity.psm1 | 15 ++- .../MSFT_SPOTenantSettings.psm1 | 13 ++- .../MSFT_SPOTheme/MSFT_SPOTheme.psm1 | 11 +- .../MSFT_TeamsChannel/MSFT_TeamsChannel.psm1 | 7 +- .../MSFT_TeamsTeam/MSFT_TeamsTeam.psm1 | 7 +- .../MSFT_TeamsUser/MSFT_TeamsUser.psm1 | 7 +- .../Office365DSC/Modules/O365DSCReverse.psm1 | 102 +++++++++--------- .../Modules/O365DSCReverseGUI.psm1 | 14 ++- .../Modules/Office365DSCUtil.psm1 | 8 +- Modules/Office365DSC/Office365DSC.psd1 | 2 +- appveyor.yml | 2 +- azure-pipelines.yml | 2 +- 23 files changed, 181 insertions(+), 124 deletions(-) diff --git a/Modules/Office365DSC/DSCResources/MSFT_O365User/MSFT_O365User.psm1 b/Modules/Office365DSC/DSCResources/MSFT_O365User/MSFT_O365User.psm1 index 3d85234701..331fd6bdae 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_O365User/MSFT_O365User.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_O365User/MSFT_O365User.psm1 @@ -102,7 +102,7 @@ function Get-TargetResource [System.Management.Automation.PSCredential] $GlobalAdminAccount ) - + Test-MSCloudLogin -Platform MSOnline -O365Credential $GlobalAdminAccount Write-Verbose -Message "Getting configuration of Office 365 User $UserPrincipalName" $nullReturn = @{ @@ -120,7 +120,6 @@ function Get-TargetResource try { Write-Verbose -Message "Getting Office 365 User $UserPrincipalName" - Connect-MsolService -Credential $GlobalAdminAccount $user = Get-MSOLUser -UserPrincipalName $UserPrincipalName -ErrorAction SilentlyContinue if ($null -eq $user) { @@ -284,7 +283,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of Office 365 User $UserPrincipalName" - Test-O365ServiceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform MSOnline $user = Get-TargetResource @PSBoundParameters $CurrentParameters = $PSBoundParameters diff --git a/Modules/Office365DSC/DSCResources/MSFT_ODSettings/MSFT_ODSettings.psm1 b/Modules/Office365DSC/DSCResources/MSFT_ODSettings/MSFT_ODSettings.psm1 index 64681c9d51..d439a95337 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_ODSettings/MSFT_ODSettings.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_ODSettings/MSFT_ODSettings.psm1 @@ -71,7 +71,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of OneDrive Settings" - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline $nullReturn = @{ CentralAdminUrl = $CentralAdminUrl @@ -239,7 +241,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of OneDrive Settings" - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline ## Configure OneDrive settings ## Parameters below are remove for the Set-SPOTenant cmdlet diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOAccessControlSettings/MSFT_SPOAccessControlSettings.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOAccessControlSettings/MSFT_SPOAccessControlSettings.psm1 index 2bf7ef30fa..6a66fd205a 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOAccessControlSettings/MSFT_SPOAccessControlSettings.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOAccessControlSettings/MSFT_SPOAccessControlSettings.psm1 @@ -69,8 +69,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of SharePoint Online Access Control Settings" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount - + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $nullReturn = @{ IsSingleInstance = 'Yes' DisplayStartASiteOption = $null @@ -189,7 +190,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of SharePoint Online Access Control Settings" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $CurrentParameters = $PSBoundParameters $CurrentParameters.Remove("CentralAdminUrl") @@ -276,8 +279,6 @@ function Test-TargetResource Write-Verbose -Message "Testing configuration of SharePoint Online Access Control Settings" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount - $CurrentValues = Get-TargetResource @PSBoundParameters Write-Verbose -Message "Current Values: $(Convert-O365DscHashtableToString -Hashtable $CurrentValues)" @@ -324,8 +325,6 @@ function Export-TargetResource [System.Management.Automation.PSCredential] $GlobalAdminAccount ) - Test-PnPOnlineConnection -GlobalAdminAccount $GlobalAdminAccount -SiteUrl $CentralAdminUrl - $result = Get-TargetResource @PSBoundParameters $result.GlobalAdminAccount = Resolve-Credentials -UserName "globaladmin" $content = "SPOAccessControlSettings " + (New-GUID).ToString() + "`r`n" diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOApp/MSFT_SPOApp.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOApp/MSFT_SPOApp.psm1 index eb20222311..5b3c8c9efd 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOApp/MSFT_SPOApp.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOApp/MSFT_SPOApp.psm1 @@ -47,7 +47,9 @@ function Get-TargetResource try { - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -Platform PnP ` + -O365Credential $GlobalAdminAccount $app = Get-PnPApp -Identity $Identity -ErrorAction SilentlyContinue if ($null -eq $app) { @@ -108,7 +110,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration for app $Identity" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -Platform PnP ` + -O365Credential $GlobalAdminAccount $currentApp = Get-TargetResource @PSBoundParameters diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOHubSite/MSFT_SPOHubSite.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOHubSite/MSFT_SPOHubSite.psm1 index 8b3f5bff3f..09913f7f36 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOHubSite/MSFT_SPOHubSite.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOHubSite/MSFT_SPOHubSite.psm1 @@ -48,8 +48,12 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration for hub site collection $Url" - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount - Test-O365ServiceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline + + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform MSOnline $nullReturn = @{ Url = $Url @@ -189,8 +193,12 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration for hub site collection $Url" - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount - Test-O365ServiceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline + + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform MSOnline try { diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOSearchManagedProperty/MSFT_SPOSearchManagedProperty.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOSearchManagedProperty/MSFT_SPOSearchManagedProperty.psm1 index 9bd399aade..6438f9de5c 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOSearchManagedProperty/MSFT_SPOSearchManagedProperty.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOSearchManagedProperty/MSFT_SPOSearchManagedProperty.psm1 @@ -99,7 +99,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration for Managed Property instance $Name" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline $nullReturn = @{ Name = $Name @@ -297,7 +299,10 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration for Managed Property instance $Name" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline + $SearchConfigTemplatePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\..\Dependencies\SearchConfigurationSettings.xml" ` -Resolve diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOSearchResultSource/MSFT_SPOSearchResultSource.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOSearchResultSource/MSFT_SPOSearchResultSource.psm1 index abc5cd48de..75ab6820f2 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOSearchResultSource/MSFT_SPOSearchResultSource.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOSearchResultSource/MSFT_SPOSearchResultSource.psm1 @@ -87,7 +87,9 @@ function Get-TargetResource Write-Verbose -Message "Setting configuration for Result Source instance $Name" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $nullReturn = @{ Name = $Name @@ -204,7 +206,10 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration for Result Source instance $Name" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP + Write-Verbose -Message "Reading SearchConfigurationSettings XML file" $SearchConfigTemplatePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\..\Dependencies\SearchConfigurationSettings.xml" ` diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOSharingSettings/MSFT_SPOSharingSettings.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOSharingSettings/MSFT_SPOSharingSettings.psm1 index 53bb5a7cec..7be307237c 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOSharingSettings/MSFT_SPOSharingSettings.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOSharingSettings/MSFT_SPOSharingSettings.psm1 @@ -111,7 +111,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration for SPO Sharing settings" - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline $nullReturn = @{ IsSingleInstance = 'Yes' @@ -291,7 +293,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration for SPO Sharing settings" - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline $CurrentParameters = $PSBoundParameters $CurrentParameters.Remove("CentralAdminUrl") @@ -450,8 +454,6 @@ function Test-TargetResource Write-Verbose -Message "Testing configuration for SPO Sharing settings" - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount - $CurrentValues = Get-TargetResource @PSBoundParameters Write-Verbose -Message "Current Values: $(Convert-O365DscHashtableToString -Hashtable $CurrentValues)" @@ -591,7 +593,6 @@ function Export-TargetResource [System.Management.Automation.PSCredential] $GlobalAdminAccount ) - Test-SPOServiceConnection -GlobalAdminAccount $GlobalAdminAccount -SPOCentralAdminUrl $CentralAdminUrl $result = Get-TargetResource @PSBoundParameters $result.GlobalAdminAccount = Resolve-Credentials -UserName "globaladmin" $content = "SPOSharingSettings " + (New-GUID).ToString() + "`r`n" diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOSite/MSFT_SPOSite.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOSite/MSFT_SPOSite.psm1 index d37039ae89..b0db856dc8 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOSite/MSFT_SPOSite.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOSite/MSFT_SPOSite.psm1 @@ -141,7 +141,9 @@ function Get-TargetResource Write-Verbose -Message "Setting configuration for site collection $Url" - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline $nullReturn = @{ Url = $Url @@ -399,7 +401,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration for site collection $Url" - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline if ($Ensure -eq "Present") { @@ -580,9 +584,6 @@ function Test-TargetResource ) Write-Verbose -Message "Testing configuration for site collection $Url" - - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount - $CurrentValues = Get-TargetResource @PSBoundParameters Write-Verbose -Message "Current Values: $(Convert-O365DscHashtableToString -Hashtable $CurrentValues)" @@ -800,8 +801,9 @@ function Set-SPOSiteConfiguration [System.Management.Automation.PSCredential] $GlobalAdminAccount ) - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount - + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline $deletedSite = Get-SPODeletedSite | Where-Object -FilterScript { $_.Url -eq $Url } if ($deletedSite) { diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOSiteDesign/MSFT_SPOSiteDesign.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOSiteDesign/MSFT_SPOSiteDesign.psm1 index 1672b1ee3f..09c1db4e08 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOSiteDesign/MSFT_SPOSiteDesign.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOSiteDesign/MSFT_SPOSiteDesign.psm1 @@ -53,8 +53,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration for SPO SiteDesign for $Title" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount - + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline $nullReturn = @{ Title = $Title SiteScriptNames = $SiteScriptNames @@ -165,7 +166,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration for SPO SiteDesign for $Title" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline $curSiteDesign = Get-TargetResource @PSBoundParameters @@ -301,7 +304,6 @@ function Export-TargetResource [System.Management.Automation.PSCredential] $GlobalAdminAccount ) - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount $result = Get-TargetResource @PSBoundParameters $result.GlobalAdminAccount = Resolve-Credentials -UserName "globaladmin" $content = " SPOSiteDesign " + (New-GUID).ToString() + "`r`n" diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOSiteDesignRights/MSFT_SPOSiteDesignRights.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOSiteDesignRights/MSFT_SPOSiteDesignRights.psm1 index f978b6b808..ce5ffdda15 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOSiteDesignRights/MSFT_SPOSiteDesignRights.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOSiteDesignRights/MSFT_SPOSiteDesignRights.psm1 @@ -33,7 +33,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration for SPO SiteDesignRights for $SiteDesignTitle" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $nullReturn = @{ SiteDesignTitle = $SiteDesignTitle @@ -115,7 +117,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration for SPO SiteDesignRights for $SiteDesignTitle" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $cursiteDesign = Get-PnPSiteDesign -Identity $SiteDesignTitle if ($null -eq $cursiteDesign) @@ -243,7 +247,6 @@ function Export-TargetResource [System.Management.Automation.PSCredential] $GlobalAdminAccount ) - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount $result = Get-TargetResource @PSBoundParameters $content = "" diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOStorageEntity/MSFT_SPOStorageEntity.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOStorageEntity/MSFT_SPOStorageEntity.psm1 index ba725d5bb8..1be778952b 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOStorageEntity/MSFT_SPOStorageEntity.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOStorageEntity/MSFT_SPOStorageEntity.psm1 @@ -41,7 +41,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration for SPO Storage Entity for $Key" - Test-PnPOnlineConnection -SiteUrl $SiteUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $SiteUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $nullReturn = @{ Key = $Key @@ -58,7 +60,11 @@ function Get-TargetResource $entityStorageParms = @{} $entityStorageParms.Add("Key", $Key) - $entityStorageParms.Add("Scope", $EntityScope) + + if ($null -ne $EntityScope -and "" -ne $EntityScope) + { + $entityStorageParms.Add("Scope", $EntityScope) + } $Entity = Get-PnPStorageEntity @entityStorageParms -ErrorAction SilentlyContinue ## Get-PnPStorageEntity seems to not return $null when not found @@ -125,7 +131,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration for SPO Storage Entity for $Key" - Test-PnPOnlineConnection -SiteUrl $SiteUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $SiteUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $curStorageEntry = Get-TargetResource @PSBoundParameters @@ -229,7 +237,6 @@ function Export-TargetResource [System.Management.Automation.PSCredential] $GlobalAdminAccount ) - Test-PnPOnlineConnection -SiteUrl $SiteUrl -GlobalAdminAccount $GlobalAdminAccount $result = Get-TargetResource @PSBoundParameters $result.GlobalAdminAccount = Resolve-Credentials -UserName "globaladmin" $content = " SPOStorageEntity " + (New-Guid).ToString() + "`r`n" diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1 index add821eeb9..b61cb9da30 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1 @@ -93,7 +93,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration for SPO Tenant" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $nullReturn = @{ IsSingleInstance = 'Yes' @@ -249,7 +251,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration for SPO Tenant" - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $CurrentParameters = $PSBoundParameters $CurrentParameters.Remove("CentralAdminUrl") @@ -358,9 +362,6 @@ function Test-TargetResource ) Write-Verbose -Message "Testing configuration for SPO Tenant" - - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount - $CurrentValues = Get-TargetResource @PSBoundParameters Write-Verbose -Message "Current Values: $(Convert-O365DscHashtableToString -Hashtable $CurrentValues)" @@ -412,8 +413,6 @@ function Export-TargetResource [System.Management.Automation.PSCredential] $GlobalAdminAccount ) - Test-PnPOnlineConnection -GlobalAdminAccount $GlobalAdminAccount -SiteUrl $CentralAdminUrl - $result = Get-TargetResource @PSBoundParameters $result.GlobalAdminAccount = Resolve-Credentials -UserName "globaladmin" $content = "SPOTenantSettings " + (New-GUID).ToString() + "`r`n" diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOTheme/MSFT_SPOTheme.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOTheme/MSFT_SPOTheme.psm1 index ff062e210b..e505bca589 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOTheme/MSFT_SPOTheme.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOTheme/MSFT_SPOTheme.psm1 @@ -32,7 +32,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration for SPO Theme $Name" - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline $nullReturn = @{ Name = $Name @@ -102,7 +104,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration for SPO Theme $Name" - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline if ($Ensure -eq "Present") { @@ -199,9 +203,6 @@ function Test-TargetResource ) Write-Verbose -Message "Testing configuration for SPO Theme $Name" - - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount - $CurrentValues = Get-TargetResource @PSBoundParameters Write-Verbose -Message "Current Values: $(Convert-O365DscHashtableToString -Hashtable $CurrentValues)" diff --git a/Modules/Office365DSC/DSCResources/MSFT_TeamsChannel/MSFT_TeamsChannel.psm1 b/Modules/Office365DSC/DSCResources/MSFT_TeamsChannel/MSFT_TeamsChannel.psm1 index c438d88dc2..a4257ea7dd 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_TeamsChannel/MSFT_TeamsChannel.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_TeamsChannel/MSFT_TeamsChannel.psm1 @@ -35,7 +35,8 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of Teams channel $DisplayName" - Test-TeamsServiceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform MicrosoftTeams $nullReturn = @{ TeamName = $TeamName @@ -124,7 +125,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of Teams channel $DisplayName" - Test-TeamsServiceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform MicrosoftTeams $channel = Get-TargetResource @PSBoundParameters @@ -244,7 +246,6 @@ function Export-TargetResource [System.Management.Automation.PSCredential] $GlobalAdminAccount ) - Test-TeamsServiceConnection -GlobalAdminAccount $GlobalAdminAccount $result = Get-TargetResource @PSBoundParameters $result.GlobalAdminAccount = Resolve-Credentials -UserName "globaladmin" $content = " TeamsChannel " + (New-GUID).ToString() + "`r`n" diff --git a/Modules/Office365DSC/DSCResources/MSFT_TeamsTeam/MSFT_TeamsTeam.psm1 b/Modules/Office365DSC/DSCResources/MSFT_TeamsTeam/MSFT_TeamsTeam.psm1 index a220a61dfa..b4ea5c6554 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_TeamsTeam/MSFT_TeamsTeam.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_TeamsTeam/MSFT_TeamsTeam.psm1 @@ -136,7 +136,8 @@ function Get-TargetResource } Write-Verbose -Message "Checking for existance of Team $DisplayName" - Test-TeamsServiceConnection -GlobalAdminAccount $GlobalAdminAccount | Out-Null + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform MicrosoftTeams $CurrentParameters = $PSBoundParameters @@ -317,7 +318,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of Team $DisplayName" - Test-TeamsServiceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform MicrosoftTeams $team = Get-TargetResource @PSBoundParameters @@ -504,7 +506,6 @@ function Export-TargetResource [System.Management.Automation.PSCredential] $GlobalAdminAccount ) - Test-TeamsServiceConnection -GlobalAdminAccount $GlobalAdminAccount $result = Get-TargetResource @PSBoundParameters $result.GlobalAdminAccount = Resolve-Credentials -UserName "globaladmin" $result.Remove("GroupID") diff --git a/Modules/Office365DSC/DSCResources/MSFT_TeamsUser/MSFT_TeamsUser.psm1 b/Modules/Office365DSC/DSCResources/MSFT_TeamsUser/MSFT_TeamsUser.psm1 index 44364297fa..17d05a35da 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_TeamsUser/MSFT_TeamsUser.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_TeamsUser/MSFT_TeamsUser.psm1 @@ -29,7 +29,8 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of member $User to Team $TeamName" - Test-TeamsServiceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform MicrosoftTeams $nullReturn = @{ User = $User @@ -108,7 +109,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of member $User to Team $TeamName" - Test-TeamsServiceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform MicrosoftTeams $team = Get-TeamByName $TeamName @@ -207,7 +209,6 @@ function Export-TargetResource [System.Management.Automation.PSCredential] $GlobalAdminAccount ) - Test-TeamsServiceConnection -GlobalAdminAccount $GlobalAdminAccount $result = Get-TargetResource @PSBoundParameters $result.GlobalAdminAccount = Resolve-Credentials -UserName "globaladmin" $content = " TeamsUser " + (New-GUID).ToString() + "`r`n" diff --git a/Modules/Office365DSC/Modules/O365DSCReverse.psm1 b/Modules/Office365DSC/Modules/O365DSCReverse.psm1 index 7a7465ca21..427f8f0e91 100644 --- a/Modules/Office365DSC/Modules/O365DSCReverse.psm1 +++ b/Modules/Office365DSC/Modules/O365DSCReverse.psm1 @@ -53,21 +53,6 @@ function Start-O365ConfigurationExtract -Value "0" ` -Description "Default Valus Used to Ensure a Configuration Data File is Generated" # Obtain central administration url from a User Principal Name - $centralAdminUrl = $null - $NeedToConnectToO365Admin = $false - foreach ($Component in $ComponentsToExtract) - { - if ($Component -like 'chckO365*') - { - $NeedToConnectToO365Admin = $true - break - } - } - if ($NeedToConnectToO365Admin -or $AllComponents) - { - Test-O365ServiceConnection -GlobalAdminAccount $GlobalAdminAccount - } - $centralAdminUrl = Get-SPOAdministrationUrl -GlobalAdminAccount $GlobalAdminAccount # Add the GlobalAdminAccount to the Credentials List @@ -445,7 +430,7 @@ function Start-O365ConfigurationExtract -Resolve Import-Module $O365UserModulePath | Out-Null - Connect-MsolService -Credential $GlobalAdminAccount + Test-MSCloudLogin -Platform MSOnline -O365Credential $GlobalAdminAccount $users = Get-MsolUser $partialContent = "" @@ -486,7 +471,8 @@ function Start-O365ConfigurationExtract Import-Module $O365GroupModulePath | Out-Null # Other Groups - Connect-AzureAD -Credential $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform AzureAD $groups = Get-AzureADGroup | Where-Object -FilterScript { $_.MailNickName -ne "00000000-0000-0000-0000-000000000000" } @@ -631,16 +617,19 @@ function Start-O365ConfigurationExtract { Write-Information "Extracting SPOApp..." $SPOAppModulePath = Join-Path -Path $PSScriptRoot ` - -ChildPath "..\DSCResources\MSFT_SPOApp\MSFT_SPOApp.psm1" ` - -Resolve + -ChildPath "..\DSCResources\MSFT_SPOApp\MSFT_SPOApp.psm1" ` + -Resolve Import-Module $SPOAppModulePath | Out-Null - Test-PnPOnlineConnection -SiteUrl $centralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $centralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP try { $tenantAppCatalogUrl = Get-PnPTenantAppCatalogUrl - Test-PnPOnlineConnection -SiteUrl $tenantAppCatalogUrl -GlobalAdminAccount $GlobalAdminAccount - + Test-MSCloudLogin -ConnectionUrl $tenantAppCatalogUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $spfxFiles = Find-PnPFile -List "AppCatalog" -Match '*.sppkg' $appFiles = Find-PnPFile -List "AppCatalog" -Match '*.app' $allFiles = $spfxFiles + $appFiles @@ -683,7 +672,10 @@ function Start-O365ConfigurationExtract $i++ } - Test-PnPOnlineConnection -SiteUrl $tenantAppCatalogUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $tenantAppCatalogUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP + foreach ($file in $allFiles) { $appInstanceUrl = $tenantAppCatalogPath + "/AppCatalog/" + $file.Name @@ -710,7 +702,9 @@ function Start-O365ConfigurationExtract Import-Module $SPOSiteModulePath | Out-Null - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline $invalidTemplates = @("SRCHCEN#0", "GROUP#0", "SPSMSITEHOST#0", "POINTPUBLISHINGHUB#0", "POINTPUBLISHINGTOPIC#0") $sites = Get-SPOSite -Limit All | Where-Object -FilterScript { $_.Template -notin $invalidTemplates } @@ -748,7 +742,10 @@ function Start-O365ConfigurationExtract $partialContent = "" if ($centralAdminUrl) { - Test-SPOServiceConnection -SPOCentralAdminUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform SharePointOnline + $hubSites = Get-SPOHubSite $i = 1 @@ -811,7 +808,9 @@ function Start-O365ConfigurationExtract -Resolve Import-Module $SPOSearchResultSourceModulePath | Out-Null - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $SearchConfig = [Xml] (Get-PnPSearchConfiguration -Scope Subscription) $sources = $SearchConfig.SearchConfigurationSettings.SearchQueryConfigurationSettings.SearchQueryConfigurationSettings.Sources.Source @@ -847,7 +846,9 @@ function Start-O365ConfigurationExtract -Resolve Import-Module $SPOSearchManagedPropertyModulePath | Out-Null - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $SearchConfig = [Xml] (Get-PnPSearchConfiguration -Scope Subscription) $properties = $SearchConfig.SearchConfigurationSettings.SearchSchemaConfigurationSettings.ManagedProperties.dictionary.KeyValueOfstringManagedPropertyInfoy6h3NzC8 @@ -882,7 +883,9 @@ function Start-O365ConfigurationExtract -Resolve Import-Module $SPOSiteDesignModulePath | Out-Null - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $siteDesigns = Get-PnPSiteDesign @@ -916,7 +919,9 @@ function Start-O365ConfigurationExtract -Resolve Import-Module $SPOSiteDesignModulePath | Out-Null - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $siteDesigns = Get-PnPSiteDesign @@ -951,47 +956,38 @@ function Start-O365ConfigurationExtract Import-Module $SPOModulePath | Out-Null - Test-PnPOnlineConnection -SiteUrl $CentralAdminUrl -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -ConnectionUrl $CentralAdminUrl ` + -O365Credential $GlobalAdminAccount ` + -Platform PnP $storageEntities = Get-PnPStorageEntity + $i = 1 foreach ($storageEntity in $storageEntities) { - Write-Information " Storage Entity {$($storageEntity.Key)}" + Write-Information " [$i/$($storageEntities.Length)] {$($storageEntity.Key)}" $DSCContent += Export-TargetResource -Key $storageEntity.Key ` - -CentralAdminUrl $centralAdminUrl ` - -GlobalAdminAccount $GlobalAdminAccount + -SiteUrl $centralAdminUrl ` + -GlobalAdminAccount $GlobalAdminAccount + $i++ } } #endregion - $NeedToConnectToTeams = $false - foreach ($Component in $ComponentsToExtract) - { - if ($Component -like 'chckTeams*') - { - $NeedToConnectToTeams = $true - break - } - } - if ($NeedToConnectToTeams -or $AllComponents) - { - Test-TeamsServiceConnection -GlobalAdminAccount $GlobalAdminAccount - $Teams = Get-Team - } - #region "TeamsTeam" if (($null -ne $ComponentsToExtract -and $ComponentsToExtract.Contains("chckTeamsTeam")) -or $AllComponents) { + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform MicrosoftTeams Write-Information "Extracting TeamsTeam..." $TeamsModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_TeamsTeam\MSFT_TeamsTeam.psm1" ` -Resolve Import-Module $TeamsModulePath | Out-Null - + $teams = Get-Team $i = 1 foreach ($team in $teams) { @@ -1008,12 +1004,15 @@ function Start-O365ConfigurationExtract $ComponentsToExtract.Contains("chckTeamsChannel")) -or $AllComponents) { + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform MicrosoftTeams Write-Information "Extracting TeamsChannel..." $TeamsChannelModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_TeamsChannel\MSFT_TeamsChannel.psm1" ` -Resolve Import-Module $TeamsChannelModulePath | Out-Null + $teams = Get-Team $j = 1 foreach ($team in $Teams) { @@ -1038,12 +1037,15 @@ function Start-O365ConfigurationExtract $ComponentsToExtract.Contains("chckTeamsUser")) -or $AllComponents) { + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform MicrosoftTeams Write-Information "Extracting TeamsUser..." $TeamsModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_TeamsUser\MSFT_TeamsUser.psm1" ` -Resolve Import-Module $TeamsModulePath | Out-Null + $teams = Get-Team $j = 1 foreach ($team in $Teams) { @@ -1103,7 +1105,7 @@ function Start-O365ConfigurationExtract #endregion #region Prompt the user for a location to save the extract and generate the files - if ($null -eq $Path) + if ($null -eq $Path -or "" -eq $Path) { $OutputDSCPath = Read-Host "Destination Path" } diff --git a/Modules/Office365DSC/Modules/O365DSCReverseGUI.psm1 b/Modules/Office365DSC/Modules/O365DSCReverseGUI.psm1 index c7b452d2d3..cf373b5978 100644 --- a/Modules/Office365DSC/Modules/O365DSCReverseGUI.psm1 +++ b/Modules/Office365DSC/Modules/O365DSCReverseGUI.psm1 @@ -219,7 +219,7 @@ function Show-O365GUI $pnlSPO = New-Object System.Windows.Forms.Panel $pnlSPO.Top = 88 + $topBannerHeight $pnlSPO.Left = $SecondColumnLeft - $pnlSPO.Height = 180 + $pnlSPO.Height = 200 $pnlSPO.Width = 300 $pnlSPO.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle @@ -287,8 +287,16 @@ function Show-O365GUI $chckSPOSiteDesignRights.Text = "Site Design Rights" $pnlSPO.Controls.Add($chckSPOSiteDesignRights) + $chckSPOStorageEntity= New-Object System.Windows.Forms.CheckBox + $chckSPOStorageEntity.Top = 160 + $chckSPOStorageEntity.AutoSize = $true; + $chckSPOStorageEntity.Name = "chckSPOStorageEntity" + $chckSPOStorageEntity.Checked = $true + $chckSPOStorageEntity.Text = "Storage Entity" + $pnlSPO.Controls.Add($chckSPOStorageEntity) + $chckSPOTheme = New-Object System.Windows.Forms.CheckBox - $chckSPOTheme.Top = 160 + $chckSPOTheme.Top = 180 $chckSPOTheme.AutoSize = $true; $chckSPOTheme.Name = "chckSPOTheme" $chckSPOTheme.Checked = $true @@ -306,7 +314,7 @@ function Show-O365GUI $pnlMain.Controls.Add($imgSC) $pnlSC = New-Object System.Windows.Forms.Panel - $pnlSC.Top = $pnlSPO.Heigth + $topBannerHeight + $imgSPO.Height + $imgSC.Height + 300 + $pnlSC.Top = $pnlSPO.Heigth + $topBannerHeight + $imgSPO.Height + $imgSC.Height + 320 $pnlSC.Left = $SecondColumnLeft $pnlSC.Height = 40 $pnlSC.Width = 300 diff --git a/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 b/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 index 49298d82cc..b84b7853b9 100644 --- a/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 +++ b/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 @@ -1471,7 +1471,9 @@ function Test-SPOServiceConnection $VerbosePreference = 'SilentlyContinue' $WarningPreference = "SilentlyContinue" Write-Verbose -Message "Verifying the LCM connection state to SharePoint Online" - Test-MSCloudLogin -Platform SharePointOnline -o365Credential $GlobalAdminAccount + Test-MSCloudLogin -Platform SharePointOnline ` + -O365Credential $GlobalAdminAccount ` + -ConnectionUrl $SPOCentralAdminUrl } function Test-PnPOnlineConnection @@ -1491,7 +1493,9 @@ function Test-PnPOnlineConnection $VerbosePreference = 'SilentlyContinue' $WarningPreference = "SilentlyContinue" Write-Verbose -Message "Verifying the LCM connection state to SharePoint Online with PnP" - Connect-PnpOnline -Url $SiteUrl -Credential $GlobalAdminAccount + Test-MSCloudLogin -Platform PnP ` + -O365Credential $GlobalAdminAccount ` + -ConnectionUrl $SiteUrl } function Test-O365ServiceConnection diff --git a/Modules/Office365DSC/Office365DSC.psd1 b/Modules/Office365DSC/Office365DSC.psd1 index 24f02c63f2..91e2d69479 100644 --- a/Modules/Office365DSC/Office365DSC.psd1 +++ b/Modules/Office365DSC/Office365DSC.psd1 @@ -56,7 +56,7 @@ @{ModuleName = "Microsoft.Online.SharePoint.PowerShell"; RequiredVersion = "16.0.8316.0"; }, @{ModuleName = "MicrosoftTeams"; RequiredVersion = "1.0.0"; }, @{ModuleName = "AzureAD"; RequiredVersion = "2.0.2.4"; }, - @{ModuleName = "MSCloudLoginAssistant"; RequiredVersion = "0.5.2"; }) + @{ModuleName = "MSCloudLoginAssistant"; RequiredVersion = "0.5.5"; }) # Assemblies that must be loaded prior to importing this module # RequiredAssemblies = @() diff --git a/appveyor.yml b/appveyor.yml index 35325dd1ac..d4b8e3147a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,7 +13,7 @@ install: Install-Module MSOnline -RequiredVersion 1.1.183.17 -Force Install-Module MicrosoftTeams -RequiredVersion 1.0.0 -Force Install-Module SharePointPnPPowerShellOnline -RequiredVersion 3.11.1907.0 -Force - Install-Module MSCloudLoginAssistant -RequiredVersion 0.5.2 -Force + Install-Module MSCloudLoginAssistant -RequiredVersion 0.5.5 -Force $webClient = new-object System.Net.WebClient $url = "https://github.com/Microsoft/Office365DSC/blob/Dev/Tests/Dependencies/SharePointOnlineManagementShell_8615-1200_x64_en-us.msi?raw=true" diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0f6b84f5e5..1da6aeafad 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -15,7 +15,7 @@ steps: inputs: targetType: 'inline' failOnStderr: true - script: Install-Module Microsoft.Online.SharePoint.PowerShell -RequiredVersion "16.0.8316.0" -Force;Install-Module AzureAD -RequiredVersion "2.0.2.4" -Force; Install-Module MicrosoftTeams -RequiredVersion "1.0.0" -Force;Install-Module SharePointPnPPowerShellOnline -RequiredVersion "3.11.1907.0" -Force;Install-Module MSOnline -Force;Install-Module ReverseDSC -Requiredversion "1.9.4.4" -Force;Install-Module MSCloudLoginAssistant -Force -RequiredVersion "0.5.2";Import-Module '$(build.artifactstagingdirectory)\BuildFiles\Tests\TestHarness.psm1' -Force;Invoke-TestHarness + script: Install-Module Microsoft.Online.SharePoint.PowerShell -RequiredVersion "16.0.8316.0" -Force;Install-Module AzureAD -RequiredVersion "2.0.2.4" -Force; Install-Module MicrosoftTeams -RequiredVersion "1.0.0" -Force;Install-Module SharePointPnPPowerShellOnline -RequiredVersion "3.11.1907.0" -Force;Install-Module MSOnline -Force;Install-Module ReverseDSC -Requiredversion "1.9.4.4" -Force;Install-Module MSCloudLoginAssistant -Force -RequiredVersion "0.5.5";Import-Module '$(build.artifactstagingdirectory)\BuildFiles\Tests\TestHarness.psm1' -Force;Invoke-TestHarness - task: PublishBuildArtifacts@1 inputs: pathtoPublish: '$(Build.ArtifactStagingDirectory)' From 7d513cc75bda2ee6b5edd4a1b08837d756af6d21 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 10 Jul 2019 20:37:49 -0400 Subject: [PATCH 2/8] Fixed Tests --- .../MSFT_EXOAcceptedDomain.psm1 | 4 +- .../MSFT_SPOTenantSettings.psm1 | 6 +- .../Office365DSC/Modules/O365DSCReverse.psm1 | 18 +++++ .../Modules/O365DSCReverseGUI.psm1 | 14 +++- .../Modules/Office365DSCUtil.psm1 | 78 +------------------ Modules/Office365DSC/Office365DSC.psd1 | 7 +- .../Office365DSC.EXOAcceptedDomain.Tests.ps1 | 2 +- .../Office365DSC.O365Group.Tests.ps1 | 4 +- .../Office365DSC.O365User.Tests.ps1 | 2 +- .../Office365DSC.ODSettings.Tests.ps1 | 2 +- ...e365DSC.SPOAccessControlSettings.Tests.ps1 | 8 +- .../Office365DSC.SPOApp.Tests.ps1 | 2 +- .../Office365DSC.SPOHubSite.Tests.ps1 | 3 +- ...e365DSC.SPOSearchManagedProperty.Tests.ps1 | 2 +- ...fice365DSC.SPOSearchResultSource.Tests.ps1 | 2 +- .../Office365DSC.SPOSharingSettings.Tests.ps1 | 16 ++-- .../Office365DSC.SPOSite.Tests.ps1 | 4 +- .../Office365DSC.SPOSiteDesign.Tests.ps1 | 2 +- ...Office365DSC.SPOSiteDesignRights.Tests.ps1 | 4 +- .../Office365DSC.SPOStorageEntity.Tests.ps1 | 2 +- .../Office365DSC.SPOTenantSettings.Tests.ps1 | 6 +- .../Office365DSC.SPOTheme.Tests.ps1 | 7 +- .../Office365DSC.TeamsChannel.Tests.ps1 | 2 +- .../Office365DSC.TeamsTeam.Tests.ps1 | 2 +- .../Office365DSC.TeamsUser.Tests.ps1 | 2 +- Tests/Unit/Stubs/Office365.psm1 | 14 ---- 26 files changed, 72 insertions(+), 143 deletions(-) diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOAcceptedDomain/MSFT_EXOAcceptedDomain.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOAcceptedDomain/MSFT_EXOAcceptedDomain.psm1 index 67e1e3659c..b3b5728a66 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOAcceptedDomain/MSFT_EXOAcceptedDomain.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOAcceptedDomain/MSFT_EXOAcceptedDomain.psm1 @@ -46,7 +46,9 @@ function Get-TargetResource Write-Verbose -Message "AcceptedDomain configuration for $($Identity) does not exist." # Check to see if $Identity matches a verified domain in the O365 Tenant - Test-O365ServiceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform AzureAD + $VerifiedDomains = Get-AzureADDomain | Where-Object -FilterScript { $_.IsVerified } $MatchingVerifiedDomain = $VerifiedDomains | Where-Object -FilterScript { $_.Name -eq $Identity } diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1 index b61cb9da30..cd085d5479 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1 @@ -415,10 +415,10 @@ function Export-TargetResource ) $result = Get-TargetResource @PSBoundParameters $result.GlobalAdminAccount = Resolve-Credentials -UserName "globaladmin" - $content = "SPOTenantSettings " + (New-GUID).ToString() + "`r`n" - $content += "{`r`n" + $content = " SPOTenantSettings " + (New-GUID).ToString() + "`r`n" + $content += " {`r`n" $content += Get-DSCBlock -Params $result -ModulePath $PSScriptRoot - $content += "}`r`n" + $content += " }`r`n" return $content } diff --git a/Modules/Office365DSC/Modules/O365DSCReverse.psm1 b/Modules/Office365DSC/Modules/O365DSCReverse.psm1 index 427f8f0e91..02c9f1c954 100644 --- a/Modules/Office365DSC/Modules/O365DSCReverse.psm1 +++ b/Modules/Office365DSC/Modules/O365DSCReverse.psm1 @@ -974,6 +974,24 @@ function Start-O365ConfigurationExtract } #endregion + #region SPOTenantSettings + if (($null -ne $ComponentsToExtract -and + $ComponentsToExtract.Contains("chckSPOTenantSettings")) -or + $AllComponents) + { + Write-Information "Extracting SPOTenantSettings..." + $SPOModulePath = Join-Path -Path $PSScriptRoot ` + -ChildPath "..\DSCResources\MSFT_SPOTenantSettings\MSFT_SPOTenantSettings.psm1" ` + -Resolve + + Import-Module $SPOModulePath | Out-Null + + $DSCContent += Export-TargetResource -ISSingleInstance 'Yes' ` + -CentralAdminUrl $centralAdminUrl ` + -GlobalAdminAccount $GlobalAdminAccount + } + #endregion + #region "TeamsTeam" if (($null -ne $ComponentsToExtract -and $ComponentsToExtract.Contains("chckTeamsTeam")) -or diff --git a/Modules/Office365DSC/Modules/O365DSCReverseGUI.psm1 b/Modules/Office365DSC/Modules/O365DSCReverseGUI.psm1 index cf373b5978..8d697c66a6 100644 --- a/Modules/Office365DSC/Modules/O365DSCReverseGUI.psm1 +++ b/Modules/Office365DSC/Modules/O365DSCReverseGUI.psm1 @@ -219,7 +219,7 @@ function Show-O365GUI $pnlSPO = New-Object System.Windows.Forms.Panel $pnlSPO.Top = 88 + $topBannerHeight $pnlSPO.Left = $SecondColumnLeft - $pnlSPO.Height = 200 + $pnlSPO.Height = 220 $pnlSPO.Width = 300 $pnlSPO.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle @@ -295,8 +295,16 @@ function Show-O365GUI $chckSPOStorageEntity.Text = "Storage Entity" $pnlSPO.Controls.Add($chckSPOStorageEntity) + $chckSPOTenantSettings = New-Object System.Windows.Forms.CheckBox + $chckSPOTenantSettings.Top = 180 + $chckSPOTenantSettings.AutoSize = $true; + $chckSPOTenantSettings.Name = "chckSPOTenantSettings" + $chckSPOTenantSettings.Checked = $true + $chckSPOTenantSettings.Text = "Tenant Settings" + $pnlSPO.Controls.Add($chckSPOTenantSettings) + $chckSPOTheme = New-Object System.Windows.Forms.CheckBox - $chckSPOTheme.Top = 180 + $chckSPOTheme.Top = 200 $chckSPOTheme.AutoSize = $true; $chckSPOTheme.Name = "chckSPOTheme" $chckSPOTheme.Checked = $true @@ -314,7 +322,7 @@ function Show-O365GUI $pnlMain.Controls.Add($imgSC) $pnlSC = New-Object System.Windows.Forms.Panel - $pnlSC.Top = $pnlSPO.Heigth + $topBannerHeight + $imgSPO.Height + $imgSC.Height + 320 + $pnlSC.Top = $pnlSPO.Heigth + $topBannerHeight + $imgSPO.Height + $imgSC.Height + 340 $pnlSC.Left = $SecondColumnLeft $pnlSC.Height = 40 $pnlSC.Width = 300 diff --git a/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 b/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 index b84b7853b9..be5d673bbf 100644 --- a/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 +++ b/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 @@ -1454,83 +1454,7 @@ function Set-EXOSafeLinksRule } } -function Test-SPOServiceConnection -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $SPOCentralAdminUrl, - - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] - $GlobalAdminAccount - ) - $VerbosePreference = 'SilentlyContinue' - $WarningPreference = "SilentlyContinue" - Write-Verbose -Message "Verifying the LCM connection state to SharePoint Online" - Test-MSCloudLogin -Platform SharePointOnline ` - -O365Credential $GlobalAdminAccount ` - -ConnectionUrl $SPOCentralAdminUrl -} - -function Test-PnPOnlineConnection -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $SiteUrl, - - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] - $GlobalAdminAccount - ) - $VerbosePreference = 'SilentlyContinue' - $WarningPreference = "SilentlyContinue" - Write-Verbose -Message "Verifying the LCM connection state to SharePoint Online with PnP" - Test-MSCloudLogin -Platform PnP ` - -O365Credential $GlobalAdminAccount ` - -ConnectionUrl $SiteUrl -} - -function Test-O365ServiceConnection -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] - $GlobalAdminAccount - ) - $VerbosePreference = 'SilentlyContinue' - $WarningPreference = "SilentlyContinue" - Write-Verbose -Message "Verifying the LCM connection state to Microsoft Azure Active Directory Services" - Test-MSCloudLogin -Platform AzureAD -o365Credential $GlobalAdminAccount - Test-MSCloudLogin -Platform MSOnline -o365Credential $GlobalAdminAccount -} -function Test-TeamsServiceConnection -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] - $GlobalAdminAccount - ) - $VerbosePreference = 'SilentlyContinue' - $WarningPreference = "SilentlyContinue" - Import-Module MicrosoftTeams -Force | Out-Null - Write-Verbose -Message "Verifying the LCM connection state to Teams" - Test-MSCloudLogin -Platform MicrosoftTeams -o365Credential $GlobalAdminAccount | Out-Null -} function Test-SecurityAndComplianceConnection { @@ -1768,7 +1692,7 @@ function Get-UsersLicenses [System.Management.Automation.PSCredential] $GlobalAdminAccount ) - Test-O365ServiceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount -Platform MSOnline Write-Verbose -Message "Store all users licenses information in Global Variable for future usage." diff --git a/Modules/Office365DSC/Office365DSC.psd1 b/Modules/Office365DSC/Office365DSC.psd1 index 91e2d69479..bb5081efd0 100644 --- a/Modules/Office365DSC/Office365DSC.psd1 +++ b/Modules/Office365DSC/Office365DSC.psd1 @@ -78,11 +78,10 @@ #FunctionsToExport = @() # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. - CmdletsToExport = 'Test-SPOServiceConnection', 'Test-Office365DSCParameterState', - 'Test-O365ServiceConnection', 'Export-O365Configuration', + CmdletsToExport = 'Test-Office365DSCParameterState', 'Export-O365Configuration', 'Get-TimeZoneNameFromID', 'Get-TimeZoneIDFromName', 'Get-LocaleIDFromName', - 'Get-LocaleNameFromID', 'Test-TeamsServiceConnection', 'Show-O365GUI', 'Start-O365ConfigurationExtract', - 'Test-PnPOnlineConnection', 'Connect-ExchangeOnline', 'Connect-SecurityAndComplianceCenter', + 'Get-LocaleNameFromID', 'Show-O365GUI', 'Start-O365ConfigurationExtract', + 'Connect-ExchangeOnline', 'Connect-SecurityAndComplianceCenter', 'New-Office365DSCLogEntry' # Variables to export from this module diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOAcceptedDomain.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOAcceptedDomain.Tests.ps1 index 5dc1cfe309..266454fb97 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOAcceptedDomain.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOAcceptedDomain.Tests.ps1 @@ -28,7 +28,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Test-O365ServiceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.O365Group.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.O365Group.Tests.ps1 index c799f3ab1f..b0adfd1485 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.O365Group.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.O365Group.Tests.ps1 @@ -20,7 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-O365ServiceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } @@ -176,7 +176,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Context -Name "ReverseDSC Tests" -Fixture { $testParams = @{ DisplayName = "Test Group" - ManagedBy = "JohnSmith@contoso.onmicrosoft.com" + ManagedBy = "JohnSmith@contoso.onmicrosoft.com" MailNickName = "TestGroup" GlobalAdminAccount = $GlobalAdminAccount } diff --git a/Tests/Unit/Office365DSC/Office365DSC.O365User.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.O365User.Tests.ps1 index 8b6d5c7f1f..445478cf97 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.O365User.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.O365User.Tests.ps1 @@ -20,7 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-O365ServiceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.ODSettings.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.ODSettings.Tests.ps1 index 9a4824fade..65ec160a30 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.ODSettings.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.ODSettings.Tests.ps1 @@ -21,7 +21,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "Pass@word1)" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-SPOServiceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } # Test contexts diff --git a/Tests/Unit/Office365DSC/Office365DSC.SPOAccessControlSettings.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SPOAccessControlSettings.Tests.ps1 index 934c03c044..f5e8693829 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SPOAccessControlSettings.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SPOAccessControlSettings.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $CmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\Office365.psm1" ` -Resolve) @@ -21,11 +21,11 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-PnPOnlineConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } - # Test contexts + # Test contexts Context -Name "PNP AccessControl settings are not configured" -Fixture { $testParams = @{ CentralAdminUrl = "https://o365dsc1-admin.sharepoint.com" @@ -117,4 +117,4 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { }#inmodulescope }#describe -Invoke-Command -ScriptBlock $Global:DscHelper.CleanupScript -NoNewScope \ No newline at end of file +Invoke-Command -ScriptBlock $Global:DscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/Office365DSC/Office365DSC.SPOApp.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SPOApp.Tests.ps1 index 87b20670e9..ef65d3dd18 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SPOApp.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SPOApp.Tests.ps1 @@ -20,7 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-SPOServiceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.SPOHubSite.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SPOHubSite.Tests.ps1 index 72843c6a0b..ae092217bd 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SPOHubSite.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SPOHubSite.Tests.ps1 @@ -20,8 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-SPOServiceConnection -MockWith { } - Mock -CommandName Test-O365ServiceConnection -MockWith { } + Mock -CommandName Test-MSCloudLogin -MockWith { } # Test contexts Context -Name "When the site doesn't already exist" -Fixture { diff --git a/Tests/Unit/Office365DSC/Office365DSC.SPOSearchManagedProperty.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SPOSearchManagedProperty.Tests.ps1 index 37552579ce..b6d48e35fe 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SPOSearchManagedProperty.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SPOSearchManagedProperty.Tests.ps1 @@ -21,7 +21,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-PnPOnlineConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } $existingValueXML = " diff --git a/Tests/Unit/Office365DSC/Office365DSC.SPOSearchResultSource.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SPOSearchResultSource.Tests.ps1 index 7843402a9d..001da384ac 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SPOSearchResultSource.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SPOSearchResultSource.Tests.ps1 @@ -21,7 +21,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-PnPOnlineConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } $existingValueXML = " diff --git a/Tests/Unit/Office365DSC/Office365DSC.SPOSharingSettings.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SPOSharingSettings.Tests.ps1 index d01c7b5ce0..c9ca5227d8 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SPOSharingSettings.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SPOSharingSettings.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $CmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\Office365.psm1" ` -Resolve) @@ -21,11 +21,11 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-SPOServiceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } - # Test contexts + # Test contexts Context -Name "SPOSharing settings are not configured" -Fixture { $testParams = @{ CentralAdminUrl = "https://o365dsc1-admin.sharepoint.com" @@ -53,7 +53,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { RequireAcceptingAccountMatchInvitedAccount = $false } - Mock -CommandName Set-SPOTenant -MockWith { + Mock -CommandName Set-SPOTenant -MockWith { return @{ SharingCapability = 'ExternalUserSharingOnly' ShowEveryoneClaim = $false @@ -78,7 +78,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } } - Mock -CommandName Get-SPOTenant -MockWith { + Mock -CommandName Get-SPOTenant -MockWith { return @{ SharingCapability = 'Disabled' ShowEveryoneClaim = $false @@ -111,7 +111,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { set-TargetResource @testParams } } - + Context -Name "ReverseDSC Tests" -Fixture { $testParams = @{ CentralAdminUrl = "https://o365dsc1-admin.sharepoint.com" @@ -139,7 +139,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { RequireAcceptingAccountMatchInvitedAccount = $false } - Mock -CommandName Get-SPOTenant -MockWith { + Mock -CommandName Get-SPOTenant -MockWith { return @{ CentralAdminUrl = "https://o365dsc1-admin.sharepoint.com" GlobalAdminAccount = $GlobalAdminAccount @@ -173,4 +173,4 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { }#inmodulescope }#describe -Invoke-Command -ScriptBlock $Global:DscHelper.CleanupScript -NoNewScope \ No newline at end of file +Invoke-Command -ScriptBlock $Global:DscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/Office365DSC/Office365DSC.SPOSite.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SPOSite.Tests.ps1 index 3db6d7f6db..a1d6ac339e 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SPOSite.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SPOSite.Tests.ps1 @@ -20,9 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-SPOServiceConnection -MockWith { } - - Mock -CommandName Connect-SPOService -MockWith { } + Mock -CommandName Test-MSCloudLogin -MockWith { } Mock -CommandName Start-Sleep -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.SPOSiteDesign.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SPOSiteDesign.Tests.ps1 index 8c67b587a2..d5b3c248dc 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SPOSiteDesign.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SPOSiteDesign.Tests.ps1 @@ -21,7 +21,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "Pass@word1)" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-PnPOnlineConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } # Test contexts diff --git a/Tests/Unit/Office365DSC/Office365DSC.SPOSiteDesignRights.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SPOSiteDesignRights.Tests.ps1 index 187118e07a..5eaf0cacce 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SPOSiteDesignRights.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SPOSiteDesignRights.Tests.ps1 @@ -21,7 +21,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "Pass@word1)" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-PnPOnlineConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } # Test contexts @@ -193,7 +193,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } } - + Context -Name "ReverseDSC Tests" -Fixture { diff --git a/Tests/Unit/Office365DSC/Office365DSC.SPOStorageEntity.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SPOStorageEntity.Tests.ps1 index aa91fac295..f5946101ef 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SPOStorageEntity.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SPOStorageEntity.Tests.ps1 @@ -21,7 +21,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "Pass@word1)" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-PnPOnlineConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } # Test contexts diff --git a/Tests/Unit/Office365DSC/Office365DSC.SPOTenantSettings.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SPOTenantSettings.Tests.ps1 index f9174a82da..e701743283 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SPOTenantSettings.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SPOTenantSettings.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $CmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\Office365.psm1" ` -Resolve) @@ -21,11 +21,11 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-PnPOnlineConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } - # Test contexts + # Test contexts Context -Name "SPO Tenant settings are not configured" -Fixture { $testParams = @{ IsSingleInstance = "Yes" diff --git a/Tests/Unit/Office365DSC/Office365DSC.SPOTheme.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SPOTheme.Tests.ps1 index 1ad011ecdd..11e409b897 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SPOTheme.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SPOTheme.Tests.ps1 @@ -20,11 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-SPOServiceConnection -MockWith { - - } - - Mock -CommandName Connect-SPOService -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } @@ -80,7 +76,6 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Test-TargetResource @testParams | Should Be $false } It "Creates the site collection in the Set method" { - #Assert-MockCalled Test-SPOServiceConnection -Exactly 5 Set-TargetResource @testParams } } diff --git a/Tests/Unit/Office365DSC/Office365DSC.TeamsChannel.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.TeamsChannel.Tests.ps1 index 394fd41ed7..091c2c7b77 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.TeamsChannel.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.TeamsChannel.Tests.ps1 @@ -21,7 +21,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "Pass@word1)" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-TeamsServiceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.TeamsTeam.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.TeamsTeam.Tests.ps1 index 7ce0e1851f..320b86f5b4 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.TeamsTeam.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.TeamsTeam.Tests.ps1 @@ -21,7 +21,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "Pass@word1)" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-TeamsServiceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } # Test contexts diff --git a/Tests/Unit/Office365DSC/Office365DSC.TeamsUser.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.TeamsUser.Tests.ps1 index 2c83d5a486..813a82b6f8 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.TeamsUser.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.TeamsUser.Tests.ps1 @@ -20,7 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "Pass@word1)" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-TeamsServiceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } # Test contexts diff --git a/Tests/Unit/Stubs/Office365.psm1 b/Tests/Unit/Stubs/Office365.psm1 index 6dad21071b..9ad5dfceeb 100644 --- a/Tests/Unit/Stubs/Office365.psm1 +++ b/Tests/Unit/Stubs/Office365.psm1 @@ -36,20 +36,6 @@ function Set-AdminAuditLogConfig{ ) } -function Test-PnPOnlineConnection{ - [CmdletBinding()] - param( - [Parameter()] - [System.String] - $GlobalAdminAccount, - - [Parameter()] - [System.String] - $SiteUrl - ) -} - - function Get-SupervisoryReviewPolicyV2 { [CmdletBinding()] From 12ca6592b5cdd423b15b6fdfe075ef147b370a77 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 10 Jul 2019 22:15:39 -0400 Subject: [PATCH 3/8] multiple fixes --- .../MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1 | 3 ++- Modules/Office365DSC/Modules/O365DSCReverse.psm1 | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1 index cd085d5479..173200de5c 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1 @@ -417,7 +417,8 @@ function Export-TargetResource $result.GlobalAdminAccount = Resolve-Credentials -UserName "globaladmin" $content = " SPOTenantSettings " + (New-GUID).ToString() + "`r`n" $content += " {`r`n" - $content += Get-DSCBlock -Params $result -ModulePath $PSScriptRoot + $currentDSCBlock = Get-DSCBlock -Params $result -ModulePath $PSScriptRoot + $content += Convert-DSCStringParamToVariable -DSCBlock $currentDSCBlock -ParameterName "GlobalAdminAccount" $content += " }`r`n" return $content } diff --git a/Modules/Office365DSC/Modules/O365DSCReverse.psm1 b/Modules/Office365DSC/Modules/O365DSCReverse.psm1 index 02c9f1c954..96ce194477 100644 --- a/Modules/Office365DSC/Modules/O365DSCReverse.psm1 +++ b/Modules/Office365DSC/Modules/O365DSCReverse.psm1 @@ -986,7 +986,7 @@ function Start-O365ConfigurationExtract Import-Module $SPOModulePath | Out-Null - $DSCContent += Export-TargetResource -ISSingleInstance 'Yes' ` + $DSCContent += Export-TargetResource -IsSingleInstance 'Yes' ` -CentralAdminUrl $centralAdminUrl ` -GlobalAdminAccount $GlobalAdminAccount } From 33f7200f35e270a6d1b19eb4fc236bd41825e501 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 11 Jul 2019 09:10:13 -0400 Subject: [PATCH 4/8] Completely offloaded authentication of all workloads to MSCloudLoginAssistant --- .../MSFT_EXOAcceptedDomain.psm1 | 8 +- .../MSFT_EXOAntiPhishPolicy.psm1 | 8 +- .../MSFT_EXOAntiPhishRule.psm1 | 9 +- .../MSFT_EXOAtpPolicyForO365.psm1 | 8 +- .../MSFT_EXOCASMailboxPlan.psm1 | 7 +- .../MSFT_EXOClientAccessRule.psm1 | 8 +- .../MSFT_EXODkimSigningConfig.psm1 | 7 +- .../MSFT_EXOHostedConnectionFilterPolicy.psm1 | 7 +- .../MSFT_EXOHostedContentFilterPolicy.psm1 | 6 +- .../MSFT_EXOHostedContentFilterRule.psm1 | 7 +- ...SFT_EXOHostedOutboundSpamFilterPolicy.psm1 | 6 +- .../MSFT_EXOMailTips/MSFT_EXOMailTips.psm1 | 6 +- .../MSFT_EXOMailboxSettings.psm1 | 7 +- .../MSFT_EXOSafeAttachmentPolicy.psm1 | 6 +- .../MSFT_EXOSafeAttachmentRule.psm1 | 7 +- .../MSFT_EXOSafeLinksPolicy.psm1 | 7 +- .../MSFT_EXOSafeLinksRule.psm1 | 6 +- .../MSFT_EXOSharedMailbox.psm1 | 6 +- .../MSFT_O365AdminAuditLogConfig.psm1 | 6 +- .../MSFT_O365Group/MSFT_O365Group.psm1 | 4 +- .../MSFT_SCComplianceTag.psm1 | 8 +- .../MSFT_SCRetentionCompliancePolicy.psm1 | 8 +- .../MSFT_SCRetentionComplianceRule.psm1 | 8 +- .../MSFT_SCSupervisoryReviewPolicy.psm1 | 8 +- .../MSFT_SCSupervisoryReviewRule.psm1 | 8 +- .../Office365DSC/Modules/O365DSCReverse.psm1 | 64 +++--- .../Modules/Office365DSCUtil.psm1 | 186 ------------------ Modules/Office365DSC/Office365DSC.psd1 | 1 - .../Office365DSC.EXOAcceptedDomain.Tests.ps1 | 2 +- .../Office365DSC.EXOAntiPhishPolicy.Tests.ps1 | 2 +- .../Office365DSC.EXOAntiPhishRule.Tests.ps1 | 2 +- ...Office365DSC.EXOAtpPolicyForO365.Tests.ps1 | 2 +- .../Office365DSC.SCComplianceTag.Tests.ps1 | 2 +- ...5DSC.SCRetentionCompliancePolicy.Tests.ps1 | 2 +- ...365DSC.SCRetentionComplianceRule.Tests.ps1 | 2 +- ...365DSC.SCSupervisoryReviewPolicy.Tests.ps1 | 2 +- ...ce365DSC.SCSupervisoryReviewRule.Tests.ps1 | 2 +- 37 files changed, 159 insertions(+), 286 deletions(-) diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOAcceptedDomain/MSFT_EXOAcceptedDomain.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOAcceptedDomain/MSFT_EXOAcceptedDomain.psm1 index b3b5728a66..7876b8b88a 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOAcceptedDomain/MSFT_EXOAcceptedDomain.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOAcceptedDomain/MSFT_EXOAcceptedDomain.psm1 @@ -36,7 +36,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of Accepted Domain for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline + $AllAcceptedDomains = Get-AcceptedDomain $AcceptedDomain = ($AllAcceptedDomains | Where-Object -FilterScript { $_.Identity -IMatch $Identity }) @@ -136,7 +138,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of Accepted Domain for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline + $AcceptedDomainParams = @{ DomainType = $DomainType Identity = $Identity diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOAntiPhishPolicy/MSFT_EXOAntiPhishPolicy.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOAntiPhishPolicy/MSFT_EXOAntiPhishPolicy.psm1 index 5b0299df3c..8c72ea8580 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOAntiPhishPolicy/MSFT_EXOAntiPhishPolicy.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOAntiPhishPolicy/MSFT_EXOAntiPhishPolicy.psm1 @@ -120,7 +120,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of AntiPhishPolicy for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline + $AntiPhishPolicies = Get-AntiPhishPolicy $AntiPhishPolicy = $AntiPhishPolicies | Where-Object -FilterScript { $_.Identity -eq $Identity } @@ -280,7 +282,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of AntiPhishPolicy for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline + $AntiPhishPolicies = Get-AntiPhishPolicy $AntiPhishPolicy = $AntiPhishPolicies | Where-Object -FilterScript { $_.Identity -eq $Identity } diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOAntiPhishRule/MSFT_EXOAntiPhishRule.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOAntiPhishRule/MSFT_EXOAntiPhishRule.psm1 index f97a3da5aa..ecd35f873f 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOAntiPhishRule/MSFT_EXOAntiPhishRule.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOAntiPhishRule/MSFT_EXOAntiPhishRule.psm1 @@ -60,8 +60,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of AntiPhishRule for $Identity" - Write-Verbose -Message "Calling Connect-ExchangeOnline function:" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline + Write-Verbose -Message "Global ExchangeOnlineSession status:" Write-Verbose -Message "$( Get-PSSession -ErrorAction SilentlyContinue | Where-Object -FilterScript { $_.Name -eq 'ExchangeOnline' } | Out-String)" @@ -181,7 +182,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of AntiPhishRule for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline + $AntiPhishRules = Get-AntiPhishRule $AntiPhishRule = $AntiPhishRules | Where-Object -FilterScript { $_.Identity -eq $Identity } diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOAtpPolicyForO365/MSFT_EXOAtpPolicyForO365.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOAtpPolicyForO365/MSFT_EXOAtpPolicyForO365.psm1 index b30a7d03ff..df27c0ec77 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOAtpPolicyForO365/MSFT_EXOAtpPolicyForO365.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOAtpPolicyForO365/MSFT_EXOAtpPolicyForO365.psm1 @@ -50,7 +50,9 @@ function Get-TargetResource throw "EXOAtpPolicyForO365 configurations MUST specify Identity value of 'Default'" } - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline + $AtpPolicies = Get-AtpPolicyForO365 $AtpPolicyForO365 = $AtpPolicies | Where-Object -FilterScript { $_.Identity -eq $Identity } @@ -140,7 +142,9 @@ function Set-TargetResource throw "EXOAtpPolicyForO365 configurations MUST specify Identity value of 'Default'" } - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline + $AtpPolicyParams = $PSBoundParameters $AtpPolicyParams.Remove('Ensure') | Out-Null $AtpPolicyParams.Remove('GlobalAdminAccount') | Out-Null diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOCASMailboxPlan/MSFT_EXOCASMailboxPlan.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOCASMailboxPlan/MSFT_EXOCASMailboxPlan.psm1 index 5c35dd7f08..552e0d2cb0 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOCASMailboxPlan/MSFT_EXOCASMailboxPlan.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOCASMailboxPlan/MSFT_EXOCASMailboxPlan.psm1 @@ -36,7 +36,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of CASMailboxPlan for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline + $CASMailboxPlans = Get-CASMailboxPlan $CASMailboxPlan = $CASMailboxPlans | Where-Object -FilterScript { $_.Identity -eq $Identity } @@ -112,7 +114,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of CASMailboxPlan for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $CASMailboxPlanParams = $PSBoundParameters $CASMailboxPlanParams.Remove('Ensure') | Out-Null diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOClientAccessRule/MSFT_EXOClientAccessRule.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOClientAccessRule/MSFT_EXOClientAccessRule.psm1 index a49c50dddb..fdbfbe176d 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOClientAccessRule/MSFT_EXOClientAccessRule.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOClientAccessRule/MSFT_EXOClientAccessRule.psm1 @@ -78,7 +78,9 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of ClientAccessRule for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline + $ClientAccessRules = Get-ClientAccessRule @@ -203,7 +205,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of ClientAccessRule for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline + $ClientAccessRules = Get-ClientAccessRule diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXODkimSigningConfig/MSFT_EXODkimSigningConfig.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXODkimSigningConfig/MSFT_EXODkimSigningConfig.psm1 index 3b01bf538e..688fdf493e 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXODkimSigningConfig/MSFT_EXODkimSigningConfig.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXODkimSigningConfig/MSFT_EXODkimSigningConfig.psm1 @@ -43,8 +43,8 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of DkimSigningConfig for $Identity" - Write-Verbose -Message "Calling Connect-ExchangeOnline function:" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline Write-Verbose -Message "Global ExchangeOnlineSession status:" Write-Verbose -Message "$( Get-PSSession -ErrorAction SilentlyContinue | Where-Object -FilterScript { $_.Name -eq 'ExchangeOnline' } | Out-String)" @@ -138,7 +138,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of DkimSigningConfig for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $DkimSigningConfigs = Get-DkimSigningConfig diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOHostedConnectionFilterPolicy/MSFT_EXOHostedConnectionFilterPolicy.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOHostedConnectionFilterPolicy/MSFT_EXOHostedConnectionFilterPolicy.psm1 index f97de96afb..82cab4fbcb 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOHostedConnectionFilterPolicy/MSFT_EXOHostedConnectionFilterPolicy.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOHostedConnectionFilterPolicy/MSFT_EXOHostedConnectionFilterPolicy.psm1 @@ -40,8 +40,8 @@ function Get-TargetResource Write-Verbose -Message "Setting configuration of HostedConnectionFilterPolicy for $Identity" - Write-Verbose -Message "Calling Connect-ExchangeOnline function:" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline Write-Verbose -Message "Global ExchangeOnlineSession status:" Write-Verbose -Message "$( Get-PSSession -ErrorAction SilentlyContinue | Where-Object -FilterScript { $_.Name -eq 'ExchangeOnline' } | Out-String)" @@ -148,7 +148,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of HostedConnectionFilterPolicy for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $HostedConnectionFilterPolicys = Get-HostedConnectionFilterPolicy diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOHostedContentFilterPolicy/MSFT_EXOHostedContentFilterPolicy.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOHostedContentFilterPolicy/MSFT_EXOHostedContentFilterPolicy.psm1 index d05cc6bdcc..d7a67e1b53 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOHostedContentFilterPolicy/MSFT_EXOHostedContentFilterPolicy.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOHostedContentFilterPolicy/MSFT_EXOHostedContentFilterPolicy.psm1 @@ -230,7 +230,8 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of HostedContentFilterPolicy for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $HostedContentFilterPolicies = Get-HostedContentFilterPolicy @@ -514,7 +515,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of HostedContentFilterPolicy for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $HostedContentFilterPolicies = Get-HostedContentFilterPolicy diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOHostedContentFilterRule/MSFT_EXOHostedContentFilterRule.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOHostedContentFilterRule/MSFT_EXOHostedContentFilterRule.psm1 index d1b7fe4fcc..f2780ae104 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOHostedContentFilterRule/MSFT_EXOHostedContentFilterRule.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOHostedContentFilterRule/MSFT_EXOHostedContentFilterRule.psm1 @@ -60,8 +60,8 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of HostedContentFilterRule for $Identity" - Write-Verbose -Message "Calling Connect-ExchangeOnline function:" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline Write-Verbose -Message "Global ExchangeOnlineSession status:" Write-Verbose -Message "$( Get-PSSession -ErrorAction SilentlyContinue | Where-Object -FilterScript { $_.Name -eq 'ExchangeOnline' } | Out-String)" @@ -182,7 +182,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of HostedContentFilterRule for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline Write-Verbose -Message "Global ExchangeOnlineSession status:" Write-Verbose -Message "$( Get-PSSession -ErrorAction SilentlyContinue | Where-Object -FilterScript { $_.Name -eq 'ExchangeOnline' } | Out-String)" diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOHostedOutboundSpamFilterPolicy/MSFT_EXOHostedOutboundSpamFilterPolicy.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOHostedOutboundSpamFilterPolicy/MSFT_EXOHostedOutboundSpamFilterPolicy.psm1 index faf489a42a..f2bdd976f8 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOHostedOutboundSpamFilterPolicy/MSFT_EXOHostedOutboundSpamFilterPolicy.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOHostedOutboundSpamFilterPolicy/MSFT_EXOHostedOutboundSpamFilterPolicy.psm1 @@ -50,7 +50,8 @@ function Get-TargetResource throw "EXOHostedOutboundSpamFilterPolicy configurations MUST specify Identity value of 'Default'" } - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $HostedOutboundSpamFilterPolicies = Get-HostedOutboundSpamFilterPolicy @@ -141,7 +142,8 @@ function Set-TargetResource throw "EXOHostedOutboundSpamFilterPolicy configurations MUST specify Identity value of 'Default'" } - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $HostedOutboundSpamFilterPolicyParams = $PSBoundParameters $HostedOutboundSpamFilterPolicyParams.Remove('Ensure') | Out-Null diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOMailTips/MSFT_EXOMailTips.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOMailTips/MSFT_EXOMailTips.psm1 index acfbe3ae6a..1bb1163227 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOMailTips/MSFT_EXOMailTips.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOMailTips/MSFT_EXOMailTips.psm1 @@ -51,7 +51,8 @@ function Get-TargetResource GlobalAdminAccount = $null } - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $OrgConfig = Get-OrganizationConfig @@ -120,7 +121,8 @@ function Set-TargetResource $OrgConfig = Get-TargetResource @PSBoundParameters - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline # CASE : MailTipsAllTipsEnabled is used diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOMailboxSettings/MSFT_EXOMailboxSettings.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOMailboxSettings/MSFT_EXOMailboxSettings.psm1 index 6a92757a5d..f2293d8946 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOMailboxSettings/MSFT_EXOMailboxSettings.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOMailboxSettings/MSFT_EXOMailboxSettings.psm1 @@ -35,7 +35,8 @@ function Get-TargetResource Ensure = "Absent" } - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $mailboxSettings = Get-MailboxRegionalConfiguration -Identity $DisplayName @@ -84,6 +85,8 @@ function Set-TargetResource ) Write-Verbose -Message "Setting configuration of Office 365 Mailbox Settings for $DisplayName" + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $currentMailbox = Get-TargetResource @PSBoundParameters @@ -101,7 +104,7 @@ function Set-TargetResource throw "The specified Time Zone {$($TimeZone)} is not valid." } - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Set-MailboxRegionalConfiguration -Identity $DisplayName ` -Language $Locale ` -TimeZone $TimeZone diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOSafeAttachmentPolicy/MSFT_EXOSafeAttachmentPolicy.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOSafeAttachmentPolicy/MSFT_EXOSafeAttachmentPolicy.psm1 index 40a3296e6f..625222896e 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOSafeAttachmentPolicy/MSFT_EXOSafeAttachmentPolicy.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOSafeAttachmentPolicy/MSFT_EXOSafeAttachmentPolicy.psm1 @@ -45,7 +45,8 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of SafeAttachmentPolicy for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $SafeAttachmentPolicies = Get-SafeAttachmentPolicy @@ -131,7 +132,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of SafeAttachmentPolicy for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $SafeAttachmentPolicyParams = $PSBoundParameters $SafeAttachmentPolicyParams.Remove('Ensure') | Out-Null diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOSafeAttachmentRule/MSFT_EXOSafeAttachmentRule.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOSafeAttachmentRule/MSFT_EXOSafeAttachmentRule.psm1 index 3a03983463..4a46c1da9e 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOSafeAttachmentRule/MSFT_EXOSafeAttachmentRule.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOSafeAttachmentRule/MSFT_EXOSafeAttachmentRule.psm1 @@ -60,8 +60,8 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of SafeAttachmentRule for $Identity" - Write-Verbose -Message "Calling Connect-ExchangeOnline function:" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline Write-Verbose -Message "Global ExchangeOnlineSession status:" Write-Verbose -Message "$( Get-PSSession -ErrorAction SilentlyContinue | Where-Object -FilterScript { $_.Name -eq 'ExchangeOnline' } | Out-String)" @@ -182,7 +182,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of SafeAttachmentRule for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $SafeAttachmentRules = Get-SafeAttachmentRule diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOSafeLinksPolicy/MSFT_EXOSafeLinksPolicy.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOSafeLinksPolicy/MSFT_EXOSafeLinksPolicy.psm1 index 4084575051..4ba3a8d964 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOSafeLinksPolicy/MSFT_EXOSafeLinksPolicy.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOSafeLinksPolicy/MSFT_EXOSafeLinksPolicy.psm1 @@ -48,8 +48,8 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of SafeLinksPolicy for $Identity" - Write-Verbose -Message "Calling Connect-ExchangeOnline function:" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline Write-Verbose -Message "Global ExchangeOnlineSession status:" Write-Verbose -Message "$( Get-PSSession -ErrorAction SilentlyContinue | Where-Object -FilterScript { $_.Name -eq 'ExchangeOnline' } | Out-String)" @@ -150,7 +150,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of SafeLinksPolicy for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $SafeLinksPolicies = Get-SafeLinksPolicy diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOSafeLinksRule/MSFT_EXOSafeLinksRule.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOSafeLinksRule/MSFT_EXOSafeLinksRule.psm1 index cd22c5943b..942830ad5d 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOSafeLinksRule/MSFT_EXOSafeLinksRule.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOSafeLinksRule/MSFT_EXOSafeLinksRule.psm1 @@ -60,7 +60,8 @@ function Get-TargetResource Write-Verbose -Message "Setting configuration of SafeLinksRule for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $SafeLinksRules = Get-SafeLinksRule $SafeLinksRule = $SafeLinksRules | Where-Object -FilterScript { $_.Identity -eq $Identity } @@ -170,7 +171,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of SafeLinksRule for $Identity" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $SafeLinksRules = Get-SafeLinksRule diff --git a/Modules/Office365DSC/DSCResources/MSFT_EXOSharedMailbox/MSFT_EXOSharedMailbox.psm1 b/Modules/Office365DSC/DSCResources/MSFT_EXOSharedMailbox/MSFT_EXOSharedMailbox.psm1 index 52756e8bf7..477080a98d 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_EXOSharedMailbox/MSFT_EXOSharedMailbox.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_EXOSharedMailbox/MSFT_EXOSharedMailbox.psm1 @@ -35,7 +35,8 @@ function Get-TargetResource Ensure = "Absent" } - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $mailboxes = Get-Mailbox $mailbox = $mailboxes | Where-Object -FilterScript { @@ -116,7 +117,8 @@ function Set-TargetResource #endregion $CurrentParameters = $PSBoundParameters - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline # CASE: Mailbox doesn't exist but should; if ($Ensure -eq "Present" -and $currentMailbox.Ensure -eq "Absent") diff --git a/Modules/Office365DSC/DSCResources/MSFT_O365AdminAuditLogConfig/MSFT_O365AdminAuditLogConfig.psm1 b/Modules/Office365DSC/DSCResources/MSFT_O365AdminAuditLogConfig/MSFT_O365AdminAuditLogConfig.psm1 index e20e3bebcd..a09ba352fb 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_O365AdminAuditLogConfig/MSFT_O365AdminAuditLogConfig.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_O365AdminAuditLogConfig/MSFT_O365AdminAuditLogConfig.psm1 @@ -33,7 +33,8 @@ function Get-TargetResource UnifiedAuditLogIngestionEnabled = $UnifiedAuditLogIngestionEnabled } - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $GetResults = Get-AdminAuditLogConfig if (-not $GetResults) @@ -90,7 +91,8 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration for Office 365 Audit Log" - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline if ($UnifiedAuditLogIngestionEnabled -eq 'Enabled') { diff --git a/Modules/Office365DSC/DSCResources/MSFT_O365Group/MSFT_O365Group.psm1 b/Modules/Office365DSC/DSCResources/MSFT_O365Group/MSFT_O365Group.psm1 index 6fbfb66517..e2e9909999 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_O365Group/MSFT_O365Group.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_O365Group/MSFT_O365Group.psm1 @@ -152,11 +152,11 @@ function Set-TargetResource ) Write-Verbose -Message "Setting configuration of Office 365 Group $DisplayName" + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $currentGroup = Get-TargetResource @PSBoundParameters - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount - if ($Ensure -eq "Present") { $CurrentParameters = $PSBoundParameters diff --git a/Modules/Office365DSC/DSCResources/MSFT_SCComplianceTag/MSFT_SCComplianceTag.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SCComplianceTag/MSFT_SCComplianceTag.psm1 index 6af706fbc7..2771762b3f 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SCComplianceTag/MSFT_SCComplianceTag.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SCComplianceTag/MSFT_SCComplianceTag.psm1 @@ -62,8 +62,8 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of ComplianceTag for $Name" - Write-Verbose -Message "Calling Test-SecurityAndComplianceConnection function:" - Test-SecurityAndComplianceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform SecurityComplianceCenter $tagObjects = Get-ComplianceTag $tagObject = $tagObjects | Where-Object { $_.Name -eq $Name } @@ -163,7 +163,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of ComplianceTag for $Name" - Test-SecurityAndComplianceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform SecurityComplianceCenter + $CurrentTag = Get-TargetResource @PSBoundParameters if (('Present' -eq $Ensure) -and ('Absent' -eq $CurrentTag.Ensure)) diff --git a/Modules/Office365DSC/DSCResources/MSFT_SCRetentionCompliancePolicy/MSFT_SCRetentionCompliancePolicy.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SCRetentionCompliancePolicy/MSFT_SCRetentionCompliancePolicy.psm1 index f264dc8e7e..a3ef20ab12 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SCRetentionCompliancePolicy/MSFT_SCRetentionCompliancePolicy.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SCRetentionCompliancePolicy/MSFT_SCRetentionCompliancePolicy.psm1 @@ -96,8 +96,8 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of RetentionCompliancePolicy for $Name" - Write-Verbose -Message "Calling Test-SecurityAndComplianceConnection function:" - Test-SecurityAndComplianceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform SecurityComplianceCenter $PolicyObjects = Get-RetentionCompliancePolicy $PolicyObject = $PolicyObjects | Where-Object {$_.Name -eq $Name} @@ -240,7 +240,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of RetentionCompliancePolicy for $Name" - Test-SecurityAndComplianceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform SecurityComplianceCenter + $CurrentPolicy = Get-TargetResource @PSBoundParameters if (('Present' -eq $Ensure) -and ('Absent' -eq $CurrentPolicy.Ensure)) diff --git a/Modules/Office365DSC/DSCResources/MSFT_SCRetentionComplianceRule/MSFT_SCRetentionComplianceRule.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SCRetentionComplianceRule/MSFT_SCRetentionComplianceRule.psm1 index 12be706ead..3745d4f1e6 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SCRetentionComplianceRule/MSFT_SCRetentionComplianceRule.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SCRetentionComplianceRule/MSFT_SCRetentionComplianceRule.psm1 @@ -55,8 +55,8 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of RetentionComplianceRule for $Name" - Write-Verbose -Message "Calling Test-SecurityAndComplianceConnection function:" - Test-SecurityAndComplianceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform SecurityComplianceCenter $RuleObjects = Get-RetentionComplianceRule $RuleObject = $RuleObjects | Where-Object {$_.Name -eq $Name} @@ -152,7 +152,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of RetentionComplianceRule for $Name" - Test-SecurityAndComplianceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform SecurityComplianceCenter + $CurrentRule = Get-TargetResource @PSBoundParameters if (('Present' -eq $Ensure) -and ('Absent' -eq $CurrentRule.Ensure)) diff --git a/Modules/Office365DSC/DSCResources/MSFT_SCSupervisoryReviewPolicy/MSFT_SCSupervisoryReviewPolicy.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SCSupervisoryReviewPolicy/MSFT_SCSupervisoryReviewPolicy.psm1 index d08b685fbe..f64829984f 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SCSupervisoryReviewPolicy/MSFT_SCSupervisoryReviewPolicy.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SCSupervisoryReviewPolicy/MSFT_SCSupervisoryReviewPolicy.psm1 @@ -29,8 +29,8 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of SupervisoryReviewPolicy for $Name" - Write-Verbose -Message "Calling Test-SecurityAndComplianceConnection function:" - Test-SecurityAndComplianceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform SecurityComplianceCenter $PolicyObjects = Get-SupervisoryReviewPolicyV2 $PolicyObject = $PolicyObjects | Where-Object {$_.Name -eq $Name} @@ -89,7 +89,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of SupervisoryReviewPolicy for $Name" - Test-SecurityAndComplianceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform SecurityComplianceCenter + $CurrentPolicy = Get-TargetResource @PSBoundParameters if (('Present' -eq $Ensure) -and ('Absent' -eq $CurrentPolicy.Ensure)) diff --git a/Modules/Office365DSC/DSCResources/MSFT_SCSupervisoryReviewRule/MSFT_SCSupervisoryReviewRule.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SCSupervisoryReviewRule/MSFT_SCSupervisoryReviewRule.psm1 index 7f0f48eba6..2450e22a55 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SCSupervisoryReviewRule/MSFT_SCSupervisoryReviewRule.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SCSupervisoryReviewRule/MSFT_SCSupervisoryReviewRule.psm1 @@ -34,8 +34,8 @@ function Get-TargetResource Write-Verbose -Message "Getting configuration of SupervisoryReviewRule for $Name" - Write-Verbose -Message "Calling Test-SecurityAndComplianceConnection function:" - Test-SecurityAndComplianceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform SecurityComplianceCenter $RuleObjects = Get-SupervisoryReviewRule $RuleObject = $RuleObjects | Where-Object {$_.Name -eq $Name} @@ -102,7 +102,9 @@ function Set-TargetResource Write-Verbose -Message "Setting configuration of SupervisoryReviewRule for $Name" - Test-SecurityAndComplianceConnection -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform SecurityComplianceCenter + $CurrentRule = Get-TargetResource @PSBoundParameters if (('Present' -eq $Ensure) -and ('Absent' -eq $CurrentRule.Ensure)) diff --git a/Modules/Office365DSC/Modules/O365DSCReverse.psm1 b/Modules/Office365DSC/Modules/O365DSCReverse.psm1 index 96ce194477..c68bcc4561 100644 --- a/Modules/Office365DSC/Modules/O365DSCReverse.psm1 +++ b/Modules/Office365DSC/Modules/O365DSCReverse.psm1 @@ -51,7 +51,7 @@ function Start-O365ConfigurationExtract Add-ConfigurationDataEntry -Node "localhost" ` -Key "ServerNumber" ` -Value "0" ` - -Description "Default Valus Used to Ensure a Configuration Data File is Generated" + -Description "Default Value Used to Ensure a Configuration Data File is Generated" # Obtain central administration url from a User Principal Name $centralAdminUrl = Get-SPOAdministrationUrl -GlobalAdminAccount $GlobalAdminAccount @@ -64,7 +64,8 @@ function Start-O365ConfigurationExtract $AllComponents) { Write-Information "Extracting O365AdminAuditLogConfig..." - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $O365AdminAuditLogConfig = Get-AdminAuditLogConfig $O365AdminAuditLogConfigModulePath = Join-Path -Path $PSScriptRoot ` @@ -110,7 +111,8 @@ function Start-O365ConfigurationExtract $AllComponents) { Write-Information "Extracting EXOCASMailboxPlan..." - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $CASMailboxPlans = Get-CASMailboxPlan $EXOCASMailboxPlanModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_EXOCASMailboxPlan\MSFT_EXOCASMailboxPlan.psm1" ` @@ -131,7 +133,8 @@ function Start-O365ConfigurationExtract $AllComponents) { Write-Information "Extracting EXOClientAccessRule..." - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $ClientAccessRules = Get-ClientAccessRule $EXOClientAccessRuleModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_EXOClientAccessRule\MSFT_EXOClientAccessRule.psm1" ` @@ -151,7 +154,8 @@ function Start-O365ConfigurationExtract $AllComponents) { Write-Information "Extracting EXODkimSigningConfig..." - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $DkimSigningConfigs = Get-DkimSigningConfig $EXODkimSigningConfigModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_EXODkimSigningConfig\MSFT_EXODkimSigningConfig.psm1" ` @@ -180,7 +184,8 @@ function Start-O365ConfigurationExtract $AllComponents) { Write-Information "Extracting EXOHostedConnectionFilterPolicy..." - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $HostedConnectionFilterPolicys = Get-HostedConnectionFilterPolicy $EXOHostedConnectionFilterPolicyModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_EXOHostedConnectionFilterPolicy\MSFT_EXOHostedConnectionFilterPolicy.psm1" ` @@ -200,7 +205,8 @@ function Start-O365ConfigurationExtract $AllComponents) { Write-Information "Extracting EXOHostedContentFilterPolicy..." - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $HostedContentFilterPolicies = Get-HostedContentFilterPolicy $EXOHostedContentFilterPolicyModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_EXOHostedContentFilterPolicy\MSFT_EXOHostedContentFilterPolicy.psm1" ` @@ -220,7 +226,8 @@ function Start-O365ConfigurationExtract $AllComponents) { Write-Information "Extracting EXOHostedContentFilterRule..." - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $HostedContentFilterRules = Get-HostedContentFilterRule $EXOHostedContentFilterRuleModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_EXOHostedContentFilterRule\MSFT_EXOHostedContentFilterRule.psm1" ` @@ -257,7 +264,8 @@ function Start-O365ConfigurationExtract if (Confirm-ImportedCmdletIsAvailable -CmdletName GetSafeAttachmentPolicy) { Write-Information "Extracting EXOSafeAttachmentPolicy..." - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $SafeAttachmentPolicies = Get-SafeAttachmentPolicy $EXOSafeAttachmentPolicyModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_EXOSafeAttachmentPolicy\MSFT_EXOSafeAttachmentPolicy.psm1" ` @@ -284,7 +292,8 @@ function Start-O365ConfigurationExtract if (Confirm-ImportedCmdletIsAvailable -CmdletName Get-SafeAttachmentRule) { Write-Information "Extracting EXOSafeAttachmentRule..." - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $SafeAttachmentRules = Get-SafeAttachmentRule $EXOSafeAttachmentRuleModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_EXOSafeAttachmentRule\MSFT_EXOSafeAttachmentRule.psm1" ` @@ -311,7 +320,8 @@ function Start-O365ConfigurationExtract if (Confirm-ImportedCmdletIsAvailable -CmdletName Get-SafeAttachmentRule) { Write-Information "Extracting EXOSafeLinksPolicy..." - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $SafeLinksPolicies = Get-SafeLinksPolicy $EXOSafeLinksPolicyModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_EXOSafeLinksPolicy\MSFT_EXOSafeLinksPolicy.psm1" ` @@ -338,7 +348,8 @@ function Start-O365ConfigurationExtract if (Confirm-ImportedCmdletIsAvailable -CmdletName Get-SafeAttachmentRule) { Write-Information "Extracting EXOSafeLinksRule..." - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $SafeLinksRules = Get-SafeLinksRule $EXOSafeLinksRuleModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_EXOSafeLinksRule\MSFT_EXOSafeLinksRule.psm1" ` @@ -363,7 +374,8 @@ function Start-O365ConfigurationExtract $AllComponents) { Write-Information "Extracting EXOMailTips..." - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $OrgConfig = Get-OrganizationConfig $organizationName = $OrgConfig.Name @@ -396,7 +408,8 @@ function Start-O365ConfigurationExtract -Resolve Import-Module $EXOSharedMailboxModulePath | Out-Null - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $mailboxes = Get-Mailbox $mailboxes = $mailboxes | Where-Object -FilterScript { $_.RecipientTypeDetails -eq "SharedMailbox" } @@ -507,7 +520,8 @@ function Start-O365ConfigurationExtract -Resolve Import-Module $EXOMailboxSettingsModulePath | Out-Null - Connect-ExchangeOnline -GlobalAdminAccount $GlobalAdminAccount + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform ExchangeOnline $mailboxes = Get-Mailbox $i = 1 @@ -548,25 +562,14 @@ function Start-O365ConfigurationExtract } #endregion - $NeedToConnectToSecurityAndCompliance = $false - foreach ($Component in $ComponentsToExtract) - { - if ($Component -like 'chckSC*') - { - $NeedToConnectToSecurityAndCompliance = $true - break - } - } - if ($NeedToConnectToSecurityAndCompliance -or $AllComponents) - { - Test-SecurityAndComplianceConnection -GlobalAdminAccount $GlobalAdminAccount - } - #region "SCRetentionCompliancePolicy" if (($null -ne $ComponentsToExtract -and $ComponentsToExtract.Contains("chckSCRetentionCompliancePolicy")) -or $AllComponents) { + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform SecurityComplianceCenter + Write-Information "Extracting SCRetentionCompliancePolicy..." $SCRetentionCompliancePolicyModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_SCRetentionCompliancePolicy\MSFT_SCRetentionCompliancePolicy.psm1" ` @@ -591,6 +594,9 @@ function Start-O365ConfigurationExtract $ComponentsToExtract.Contains("chckSCRetentionComplianceRule")) -or $AllComponents) { + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform SecurityComplianceCenter + Write-Information "Extracting SCRetentionComplianceRule..." $SCRetentionComplianceRuleModulePath = Join-Path -Path $PSScriptRoot ` -ChildPath "..\DSCResources\MSFT_SCRetentionComplianceRule\MSFT_SCRetentionComplianceRule.psm1" ` diff --git a/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 b/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 index be5d673bbf..bca11bad15 100644 --- a/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 +++ b/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 @@ -977,162 +977,6 @@ function Get-TeamByName } return $team } -function Connect-ExchangeOnline -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] - $GlobalAdminAccount - ) - $VerbosePreference = 'SilentlyContinue' - $WarningPreference = "Continue" - $ClosedOrBrokenSessions = Get-PSSession -ErrorAction SilentlyContinue | Where-Object -FilterScript { $_.State -ne 'Opened' } - if ($ClosedOrBrokenSessions) - { - Write-Verbose -Message "Found Existing Unusable Session(s)." - foreach ($SessionToBeClosed in $ClosedOrBrokenSessions) - { - Write-Verbose -Message "Closing Session: $(($SessionToBeClosed).InstanceId)" - $SessionToBeClosed | Remove-PSSession - } - } - - $Global:OpenExchangeSession = Get-PSSession -Name 'ExchangeOnline' -ErrorAction SilentlyContinue | Where-Object -FilterScript { $_.State -eq 'Opened' } - if ($null -eq $Global:OpenExchangeSession) - { - try - { - $PowerShellConnections = Get-NetTCPConnection | Where-Object -FilterScript { $_.OwningProcess -eq $PID -and $_.RemotePort -eq '443' -and $_.State -ne 'Established' } - - while ($PowerShellConnections) - { - Write-Verbose -Message "This process is using the following connections in a non-Established state: $($PowerShellConnections | Out-String)" - Write-Verbose -Message "Waiting for closing connections to close..." - Get-PSSession -Name 'ExchangeOnline' -ErrorAction SilentlyContinue | Remove-PSSession - Start-Sleep -seconds 1 - $CheckConnectionsWithoutKillingWhileLoop = Get-NetTCPConnection | Where-Object -FilterScript { $_.OwningProcess -eq $PID -and $_.RemotePort -eq '443' -and $_.State -ne 'Established' } - if (-not $CheckConnectionsWithoutKillingWhileLoop) { - Write-Verbose -Message "Connections have closed. Waiting 5 more seconds..." - Start-Sleep -seconds 5 - $PowerShellConnections = Get-NetTCPConnection | Where-Object -FilterScript { $_.OwningProcess -eq $PID -and $_.RemotePort -eq '443' -and $_.State -ne 'Established' } - } - } - - if ($Global:ExchangeOnlineSession.State -eq "Closed") - { - Remove-PSSession $Global:ExchangeOnlineSession - $Global:ExchangeOnlineSession = $null - } - - while ($null -eq $Global:ExchangeOnlineSession) - { - Write-Verbose -Message "Creating new EXO Session" - $Global:ExchangeOnlineSession = New-PSSession -Name 'ExchangeOnline' -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $GlobalAdminAccount -Authentication Basic -AllowRedirection -ErrorAction SilentlyContinue - - if ($null -eq $Global:ExchangeOnlineSession) - { - Write-Warning "Exceeded max number of connections. Waiting 60 seconds" - Start-Sleep 60 - } - } - - if ($null -eq $Global:ExchangeOnlineModules) - { - Write-Verbose -Message "Importing all commands into the EXO Session" - $Global:ExchangeOnlineModules = Import-PSSession $Global:ExchangeOnlineSession -AllowClobber - Import-Module $Global:ExchangeOnlineModules -Global | Out-Null - } - } - catch - { - $ExceptionMessage = $_.Exception - $Error.Clear() - $VerbosePreference = 'SilentlyContinue' - if ($ExceptionMessage -imatch 'Please wait for [0-9]* seconds' ) - { - Write-Verbose -Message "Waiting for available runspace..." - [regex]$WaitTimePattern = 'Please wait for [0-9]* seconds' - $WaitTimePatternMatch = (($WaitTimePattern.Match($ExceptionMessage)).Value | Select-String -Pattern '[0-9]*' -AllMatches ) - $WaitTimeInSeconds = ($WaitTimePatternMatch | ForEach-Object {$_.Matches} | Where-Object -FilterScript { $_.Value -NotLike $null }).Value - Write-Verbose -Message "Waiting for requested $WaitTimeInSeconds seconds..." - Start-Sleep -Seconds ($WaitTimeInSeconds + 1) - try - { - Write-Verbose -Message "Opening New ExchangeOnline Session." - $PowerShellConnections = Get-NetTCPConnection | Where-Object -FilterScript { $_.OwningProcess -eq $PID -and $_.RemotePort -eq '443' -and $_.State -ne 'Established' } - while ($PowerShellConnections) - { - Write-Verbose -Message "This process is using the following connections in a non-Established state: $($PowerShellConnections | Out-String)" - Write-Verbose -Message "Waiting for closing connections to close..." - Get-PSSession -Name 'ExchangeOnline' -ErrorAction SilentlyContinue | Remove-PSSession - Start-Sleep -seconds 1 - $CheckConnectionsWithoutKillingWhileLoop = Get-NetTCPConnection | Where-Object -FilterScript { $_.OwningProcess -eq $PID -and $_.RemotePort -eq '443' -and $_.State -ne 'Established' } - if (-not $CheckConnectionsWithoutKillingWhileLoop) { - Write-Verbose -Message "Connections have closed. Waiting 5 more seconds..." - Start-Sleep -seconds 5 - $PowerShellConnections = Get-NetTCPConnection | Where-Object -FilterScript { $_.OwningProcess -eq $PID -and $_.RemotePort -eq '443' -and $_.State -ne 'Established' } - } - } - $VerbosePreference = 'SilentlyContinue' - $Global:ExchangeOnlineSession = $null - while (-not $Global:ExchangeOnlineSession) - { - $Global:ExchangeOnlineSession = New-PSSession -Name 'ExchangeOnline' -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $GlobalAdminAccount -Authentication Basic -AllowRedirection -ErrorAction SilentlyContinue - } - - $Global:ExchangeOnlineModules = Import-PSSession $Global:ExchangeOnlineSession -AllowClobber -ErrorAction SilentlyContinue - - $ExchangeOnlineModuleImport = Import-Module $ExchangeOnlineModules -Global -ErrorAction SilentlyContinue - } - catch - { - $VerbosePreference = 'SilentlyContinue' - $WarningPreference = "SilentlyContinue" - $Global:ExchangeOnlineSession = $null - Close-SessionsAndReturnError -ExceptionMessage $_.Exception - $Message = "Can't open Exchange Online session from Connect-ExchangeOnline" - New-Office365DSCLogEntry -Error $_ -Message $Message - } - } - else - { - Write-Verbose $_.Exception - $VerbosePreference = 'SilentlyContinue' - Get-PSSession -Name 'ExchangeOnline' -ErrorAction SilentlyContinue | Remove-PSSession - Write-Verbose -Message "Exchange Online connection failed." - Write-Verbose -Message "Waiting 60 seconds..." - Start-Sleep -Seconds 60 - try - { - Write-Verbose -Message "Opening New ExchangeOnline Session." - $VerbosePreference = 'SilentlyContinue' - Get-PSSession -Name 'ExchangeOnline' -ErrorAction SilentlyContinue | Remove-PSSession -ErrorAction SilentlyContinue - $Global:ExchangeOnlineSession = New-PSSession -Name 'ExchangeOnline' -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $GlobalAdminAccount -Authentication Basic -AllowRedirection - $Global:ExchangeOnlineModules = Import-PSSession $Global:ExchangeOnlineSession -AllowClobber -ErrorAction SilentlyContinue - - $ExchangeOnlineModuleImport = Import-Module $ExchangeOnlineModules -Global -ErrorAction SilentlyContinue - } - catch - { - $VerbosePreference = 'SilentlyContinue' - $WarningPreference = "SilentlyContinue" - $Global:ExchangeOnlineSession = $null - Close-SessionsAndReturnError -ExceptionMessage $_.Exception - } - } - } - } - else - { - Write-Verbose -Message "Using Existing ExchangeOnline Session." - $Global:OpenExchangeSession = Get-PSSession -Name 'ExchangeOnline' -ErrorAction SilentlyContinue | Where-Object -FilterScript { $_.State -eq 'Opened' } - $VerbosePreference = 'SilentlyContinue' - $WarningPreference = "SilentlyContinue" - } -} function Convert-O365DscHashtableToString { @@ -1456,36 +1300,6 @@ function Set-EXOSafeLinksRule -function Test-SecurityAndComplianceConnection -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] - $GlobalAdminAccount - ) - $VerbosePreference = 'SilentlyContinue' - $WarningPreference = "SilentlyContinue" - - $Global:SessionSecurityCompliance = Get-PSSession | Where-Object{$_.ComputerName -like "*.ps.compliance.protection.outlook.com"} - if ($null -eq $Global:SessionSecurityCompliance) - { - Write-Verbose -Message "Session to Security & Compliance already exists, re-using existing session" - $Global:SessionSecurityCompliance = New-PSSession -ConfigurationName "Microsoft.Exchange" ` - -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ ` - -Credential $GlobalAdminAccount ` - -Authentication Basic ` - -AllowRedirection - - $Global:SCModule = Import-PSSession $Global:SessionSecurityCompliance ` - -ErrorAction SilentlyContinue ` - -AllowClobber - - Import-Module $Global:SCModule -Global | Out-Null - } -} function Test-Office365DSCParameterState { diff --git a/Modules/Office365DSC/Office365DSC.psd1 b/Modules/Office365DSC/Office365DSC.psd1 index bb5081efd0..49622b9c85 100644 --- a/Modules/Office365DSC/Office365DSC.psd1 +++ b/Modules/Office365DSC/Office365DSC.psd1 @@ -81,7 +81,6 @@ CmdletsToExport = 'Test-Office365DSCParameterState', 'Export-O365Configuration', 'Get-TimeZoneNameFromID', 'Get-TimeZoneIDFromName', 'Get-LocaleIDFromName', 'Get-LocaleNameFromID', 'Show-O365GUI', 'Start-O365ConfigurationExtract', - 'Connect-ExchangeOnline', 'Connect-SecurityAndComplianceCenter', 'New-Office365DSCLogEntry' # Variables to export from this module diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOAcceptedDomain.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOAcceptedDomain.Tests.ps1 index 266454fb97..a0d9418c7f 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOAcceptedDomain.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOAcceptedDomain.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishPolicy.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishPolicy.Tests.ps1 index 8e47454383..a14fd3dff3 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishPolicy.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishPolicy.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishRule.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishRule.Tests.ps1 index eae834cf8b..0c4c6809b6 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishRule.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishRule.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOAtpPolicyForO365.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOAtpPolicyForO365.Tests.ps1 index 93d0770efc..8fff64624b 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOAtpPolicyForO365.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOAtpPolicyForO365.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.SCComplianceTag.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SCComplianceTag.Tests.ps1 index bdab09b548..e346779d8c 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SCComplianceTag.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SCComplianceTag.Tests.ps1 @@ -20,7 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-SecurityAndComplianceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.SCRetentionCompliancePolicy.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SCRetentionCompliancePolicy.Tests.ps1 index 263e43b06a..47058df9b6 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SCRetentionCompliancePolicy.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SCRetentionCompliancePolicy.Tests.ps1 @@ -20,7 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-SecurityAndComplianceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.SCRetentionComplianceRule.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SCRetentionComplianceRule.Tests.ps1 index 87a5b3a7fc..487c303208 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SCRetentionComplianceRule.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SCRetentionComplianceRule.Tests.ps1 @@ -20,7 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-SecurityAndComplianceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.SCSupervisoryReviewPolicy.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SCSupervisoryReviewPolicy.Tests.ps1 index 3d1025000c..8db3397a97 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SCSupervisoryReviewPolicy.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SCSupervisoryReviewPolicy.Tests.ps1 @@ -20,7 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-SecurityAndComplianceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.SCSupervisoryReviewRule.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.SCSupervisoryReviewRule.Tests.ps1 index d8a97a0175..94df75bddc 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.SCSupervisoryReviewRule.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.SCSupervisoryReviewRule.Tests.ps1 @@ -20,7 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Test-SecurityAndComplianceConnection -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } From 111b8fd75612be6aa488eb8dd432a0d3a0dfc7eb Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 11 Jul 2019 14:56:27 -0400 Subject: [PATCH 5/8] Fixes --- .../MSFT_O365Group/MSFT_O365Group.psm1 | 3 +- .../MSFT_SPOSite/MSFT_SPOSite.psm1 | 3 +- .../MSFT_SPOStorageEntity.psm1 | 6 +- .../Office365DSC/Modules/O365DSCReverse.psm1 | 4 +- .../Office365DSC.EXOAcceptedDomain.Tests.ps1 | 4 - .../Office365DSC.EXOCASMailboxPlan.Tests.ps1 | 2 +- ...Office365DSC.EXOClientAccessRule.Tests.ps1 | 2 +- ...ffice365DSC.EXODkimSigningConfig.Tests.ps1 | 2 +- ....EXOHostedConnectionFilterPolicy.Tests.ps1 | 2 +- ...DSC.EXOHostedContentFilterPolicy.Tests.ps1 | 2 +- ...65DSC.EXOHostedContentFilterRule.Tests.ps1 | 2 +- ...XOHostedOutboundSpamFilterPolicy.Tests.ps1 | 2 +- .../Office365DSC.EXOMailTips.Tests.ps1 | 2 +- .../Office365DSC.EXOMailboxSettings.Tests.ps1 | 2 +- ...ce365DSC.EXOSafeAttachmentPolicy.Tests.ps1 | 2 +- ...fice365DSC.EXOSafeAttachmentRule.Tests.ps1 | 2 +- .../Office365DSC.EXOSafeLinksPolicy.Tests.ps1 | 2 +- .../Office365DSC.EXOSafeLinksRule.Tests.ps1 | 2 +- .../Office365DSC.EXOSharedMailbox.Tests.ps1 | 2 +- ...ce365DSC.O365AdminAuditLogConfig.Tests.ps1 | 6 +- .../Office365DSC.O365Group.Tests.ps1 | 8 - .../Office365DSC.O365User.Tests.ps1 | 5 - Tests/Unit/Stubs/Office365.psm1 | 148 ------------------ 23 files changed, 24 insertions(+), 191 deletions(-) diff --git a/Modules/Office365DSC/DSCResources/MSFT_O365Group/MSFT_O365Group.psm1 b/Modules/Office365DSC/DSCResources/MSFT_O365Group/MSFT_O365Group.psm1 index e2e9909999..851d18b314 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_O365Group/MSFT_O365Group.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_O365Group/MSFT_O365Group.psm1 @@ -45,7 +45,8 @@ function Get-TargetResource Ensure = "Absent" } - Connect-AzureAD -Credential $GlobalAdminAccount | Out-Null + Test-MSCloudLogin -O365Credential $GlobalAdminAccount ` + -Platform AzureAD $ADGroup = Get-AzureADGroup -SearchString $MailNickName -ErrorAction SilentlyContinue if ($null -eq $ADGroup) diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOSite/MSFT_SPOSite.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOSite/MSFT_SPOSite.psm1 index b0db856dc8..9e887bf1fa 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOSite/MSFT_SPOSite.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOSite/MSFT_SPOSite.psm1 @@ -196,6 +196,7 @@ function Get-TargetResource } if ($site.HubSiteId -ne "00000000-0000-0000-0000-000000000000") { + $hubId = $site.HubSiteId $hubSites = Get-SPOHubSite $hubSite = $hubSites | Where-Object -FilterScript { $_.Id -eq $site.HubSiteId } @@ -205,7 +206,7 @@ function Get-TargetResource } else { - throw "Cannot find Hub site with ID: $($site.HubSiteId)" + Write-Warning "The site {$Url} is associated with Hub Site {$hubId} which no longer exists." } } diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOStorageEntity/MSFT_SPOStorageEntity.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOStorageEntity/MSFT_SPOStorageEntity.psm1 index 1be778952b..5638e581ba 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOStorageEntity/MSFT_SPOStorageEntity.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOStorageEntity/MSFT_SPOStorageEntity.psm1 @@ -15,7 +15,7 @@ function Get-TargetResource [Parameter()] [ValidateSet("Tenant", "Site")] [System.String] - $EntityScope, + $EntityScope = "Tenant", [Parameter()] [System.String] @@ -105,7 +105,7 @@ function Set-TargetResource [Parameter()] [ValidateSet("Tenant", "Site")] [System.String] - $EntityScope, + $EntityScope = "Tenant", [Parameter()] [System.String] @@ -173,7 +173,7 @@ function Test-TargetResource [Parameter()] [ValidateSet("Tenant", "Site")] [System.String] - $EntityScope, + $EntityScope = "Tenant", [Parameter()] [System.String] diff --git a/Modules/Office365DSC/Modules/O365DSCReverse.psm1 b/Modules/Office365DSC/Modules/O365DSCReverse.psm1 index c68bcc4561..3028f525bd 100644 --- a/Modules/Office365DSC/Modules/O365DSCReverse.psm1 +++ b/Modules/Office365DSC/Modules/O365DSCReverse.psm1 @@ -937,8 +937,8 @@ function Start-O365ConfigurationExtract { Write-Information " - [$i/$($siteDesigns.Length)] $($siteDesign.Title)" $partialContent += Export-TargetResource -SiteDesignTitle $siteDesign.Title ` - -CentralAdminUrl $centralAdminUrl ` - -GlobalAdminAccount $GlobalAdminAccount + -CentralAdminUrl $CentralAdminUrl ` + -GlobalAdminAccount $GlobalAdminAccount if ($partialContent.ToLower().Contains($centralAdminUrl.ToLower())) { diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOAcceptedDomain.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOAcceptedDomain.Tests.ps1 index a0d9418c7f..aa36923359 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOAcceptedDomain.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOAcceptedDomain.Tests.ps1 @@ -24,10 +24,6 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName MSCloudLogin -MockWith { - - } - Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOCASMailboxPlan.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOCASMailboxPlan.Tests.ps1 index 2a45659b24..b3db651a8e 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOCASMailboxPlan.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOCASMailboxPlan.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOClientAccessRule.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOClientAccessRule.Tests.ps1 index a371c476bd..104c213d70 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOClientAccessRule.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOClientAccessRule.Tests.ps1 @@ -22,7 +22,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXODkimSigningConfig.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXODkimSigningConfig.Tests.ps1 index 223a357fb8..de20edff9d 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXODkimSigningConfig.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXODkimSigningConfig.Tests.ps1 @@ -22,7 +22,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOHostedConnectionFilterPolicy.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOHostedConnectionFilterPolicy.Tests.ps1 index cfc300c307..52b789294f 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOHostedConnectionFilterPolicy.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOHostedConnectionFilterPolicy.Tests.ps1 @@ -22,7 +22,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOHostedContentFilterPolicy.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOHostedContentFilterPolicy.Tests.ps1 index b93b557c49..4249fddc43 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOHostedContentFilterPolicy.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOHostedContentFilterPolicy.Tests.ps1 @@ -22,7 +22,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOHostedContentFilterRule.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOHostedContentFilterRule.Tests.ps1 index c709a8df6f..ed40a140e1 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOHostedContentFilterRule.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOHostedContentFilterRule.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOHostedOutboundSpamFilterPolicy.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOHostedOutboundSpamFilterPolicy.Tests.ps1 index d1a54f1c07..9bb5d39288 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOHostedOutboundSpamFilterPolicy.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOHostedOutboundSpamFilterPolicy.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOMailTips.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOMailTips.Tests.ps1 index 4cd9e2bd14..11709ad635 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOMailTips.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOMailTips.Tests.ps1 @@ -20,7 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOMailboxSettings.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOMailboxSettings.Tests.ps1 index 1c60819dce..46a279fdda 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOMailboxSettings.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOMailboxSettings.Tests.ps1 @@ -20,7 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOSafeAttachmentPolicy.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOSafeAttachmentPolicy.Tests.ps1 index ef6efaab88..e19ee2a35b 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOSafeAttachmentPolicy.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOSafeAttachmentPolicy.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOSafeAttachmentRule.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOSafeAttachmentRule.Tests.ps1 index ff6b8c6b80..3da30d0cea 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOSafeAttachmentRule.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOSafeAttachmentRule.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOSafeLinksPolicy.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOSafeLinksPolicy.Tests.ps1 index c863b3f2a8..7aaca94f74 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOSafeLinksPolicy.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOSafeLinksPolicy.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOSafeLinksRule.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOSafeLinksRule.Tests.ps1 index c4d9e76813..b19f6785b0 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOSafeLinksRule.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOSafeLinksRule.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOSharedMailbox.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOSharedMailbox.Tests.ps1 index d5d79b6676..f61ff2e349 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOSharedMailbox.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOSharedMailbox.Tests.ps1 @@ -20,7 +20,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ("tenantadmin", $secpasswd) - Mock -CommandName Connect-ExchangeOnline -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.O365AdminAuditLogConfig.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.O365AdminAuditLogConfig.Tests.ps1 index 2bc502bedc..d6324cb258 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.O365AdminAuditLogConfig.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.O365AdminAuditLogConfig.Tests.ps1 @@ -21,11 +21,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $secpasswd = ConvertTo-SecureString "test@password1" -AsPlainText -Force $GlobalAdminAccount = New-Object System.Management.Automation.PSCredential ('tenantadmin', $secpasswd) - Mock -CommandName Connect-ExchangeOnline -MockWith { - - } - - Mock -CommandName Connect-SecurityAndComplianceCenter -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.O365Group.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.O365Group.Tests.ps1 index b0adfd1485..388d82d80b 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.O365Group.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.O365Group.Tests.ps1 @@ -24,14 +24,6 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName Connect-ExchangeOnline -MockWith { - - } - - Mock -CommandName Connect-AzureAD -MockWith { - - } - # Test contexts Context -Name "When the group doesn't already exist" -Fixture { $testParams = @{ diff --git a/Tests/Unit/Office365DSC/Office365DSC.O365User.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.O365User.Tests.ps1 index 445478cf97..a6524bc7f7 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.O365User.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.O365User.Tests.ps1 @@ -23,11 +23,6 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Mock -CommandName Test-MSCloudLogin -MockWith { } - - Mock -CommandName Connect-ExchangeOnline -MockWith { - - } - # Test contexts Context -Name "When the user doesn't already exist" -Fixture { $testParams = @{ diff --git a/Tests/Unit/Stubs/Office365.psm1 b/Tests/Unit/Stubs/Office365.psm1 index 9ad5dfceeb..6c57223c4f 100644 --- a/Tests/Unit/Stubs/Office365.psm1 +++ b/Tests/Unit/Stubs/Office365.psm1 @@ -963,59 +963,6 @@ param( } - function Global:Connect-ExchangeOnline -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] - $GlobalAdminAccount - ) - -} -function Global:Connect-SecurityAndComplianceCenter -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] - $GlobalAdminAccount - ) - -} - -function Connect-SPOService { - [CmdletBinding()] -param( - [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] - [ValidateNotNullOrEmpty()] - [object] - ${Url}, - - [Parameter(Position=1, ValueFromPipeline=$true)] - [object] - ${Credential}, - - [Parameter(Position=2)] - [string] - ${ClientTag}, - - [Parameter(ParameterSetName='AuthenticationLocation', Position=3)] - [object] - ${Region}, - - [Parameter(ParameterSetName='AuthenticationUrl', Mandatory=$true, Position=3)] - [string] - ${AuthenticationUrl}) - - - } - - function ConvertTo-SPOMigrationEncryptedPackage { [CmdletBinding()] param( @@ -1143,13 +1090,6 @@ param() } -function Disconnect-SPOService { - [CmdletBinding()] -param() - - - } - function Enable-SPOTenantServicePrincipal { [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] @@ -5954,33 +5894,6 @@ param( } - -function Connect-MsolService { - [CmdletBinding(DefaultParameterSetName='None__0')] -param( - [Parameter(ParameterSetName='Credential')] - [pscredential] - ${Credential}, - - [Parameter(ParameterSetName='AccessToken')] - [Alias('AccessToken')] - [string] - ${AdGraphAccessToken}, - - [Parameter(ParameterSetName='AccessToken')] - [string] - ${MsGraphAccessToken}, - - [Parameter(ParameterSetName='None__0')] - [Parameter(ParameterSetName='Credential')] - [Parameter(ParameterSetName='AccessToken')] - [object] - ${AzureEnvironment}) - - - } - - function Convert-MsolDomainToFederated { [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] param( @@ -8359,67 +8272,6 @@ param( } -function Connect-AzureAD { - [CmdletBinding(DefaultParameterSetName='UserCredential', SupportsShouldProcess=$true, ConfirmImpact='Medium')] -param( - [ValidateNotNullOrEmpty()] - [object] - ${AzureEnvironmentName}, - - [Parameter(ParameterSetName='UserCredential')] - [Parameter(ParameterSetName='ServicePrincipalCertificate', Mandatory=$true)] - [Parameter(ParameterSetName='AccessToken')] - [Alias('Domain','TenantDomain')] - [ValidateNotNullOrEmpty()] - [string] - ${TenantId}, - - [Parameter(ParameterSetName='UserCredential')] - [pscredential] - ${Credential}, - - [Parameter(ParameterSetName='ServicePrincipalCertificate', Mandatory=$true)] - [string] - ${CertificateThumbprint}, - - [Parameter(ParameterSetName='ServicePrincipalCertificate', Mandatory=$true)] - [string] - ${ApplicationId}, - - [Parameter(ParameterSetName='AccessToken', Mandatory=$true)] - [ValidateNotNullOrEmpty()] - [string] - ${AadAccessToken}, - - [Parameter(ParameterSetName='AccessToken')] - [ValidateNotNullOrEmpty()] - [string] - ${MsAccessToken}, - - [Parameter(ParameterSetName='AccessToken', Mandatory=$true)] - [Parameter(ParameterSetName='UserCredential')] - [ValidateNotNullOrEmpty()] - [string] - ${AccountId}, - - [object] - ${LogLevel}, - - [string] - ${LogFilePath}) - - - } - - -function Disconnect-AzureAD { - [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] -param() - - - } - - function Enable-AzureADDirectoryRole { [CmdletBinding(DefaultParameterSetName='InvokeByDynamicParameters')] param() From d87a9a4c3fed546484eaf9399cb2c8d703ca7867 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 11 Jul 2019 17:13:47 -0400 Subject: [PATCH 6/8] Fixes App path to be relative to the config --- .../DSCResources/MSFT_SPOApp/MSFT_SPOApp.psm1 | 3 ++- Modules/Office365DSC/Modules/O365DSCReverse.psm1 | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Modules/Office365DSC/DSCResources/MSFT_SPOApp/MSFT_SPOApp.psm1 b/Modules/Office365DSC/DSCResources/MSFT_SPOApp/MSFT_SPOApp.psm1 index 5b3c8c9efd..a9eaf17efb 100644 --- a/Modules/Office365DSC/DSCResources/MSFT_SPOApp/MSFT_SPOApp.psm1 +++ b/Modules/Office365DSC/DSCResources/MSFT_SPOApp/MSFT_SPOApp.psm1 @@ -212,7 +212,8 @@ function Export-TargetResource $content = " SPOApp " + (New-GUID).ToString() + "`r`n" $content += " {`r`n" $currentDSCBlock = Get-DSCBlock -Params $result -ModulePath $PSScriptRoot - $content += Convert-DSCStringParamToVariable -DSCBlock $currentDSCBlock -ParameterName "GlobalAdminAccount" + $convertedContent = Convert-DSCStringParamToVariable -DSCBlock $currentDSCBlock -ParameterName "GlobalAdminAccount" + $content += $convertedContent $content += " }`r`n" return $content } diff --git a/Modules/Office365DSC/Modules/O365DSCReverse.psm1 b/Modules/Office365DSC/Modules/O365DSCReverse.psm1 index 3028f525bd..94c4263084 100644 --- a/Modules/Office365DSC/Modules/O365DSCReverse.psm1 +++ b/Modules/Office365DSC/Modules/O365DSCReverse.psm1 @@ -52,6 +52,7 @@ function Start-O365ConfigurationExtract -Key "ServerNumber" ` -Value "0" ` -Description "Default Value Used to Ensure a Configuration Data File is Generated" + # Obtain central administration url from a User Principal Name $centralAdminUrl = Get-SPOAdministrationUrl -GlobalAdminAccount $GlobalAdminAccount @@ -655,7 +656,7 @@ function Start-O365ConfigurationExtract if ($null -ne $app) { $partialContent = Export-TargetResource -Identity $identity ` - -Path ("`$(`$ConfigurationData.NonNodeData.AppsLocation)" + $file.Name) ` + -Path ("`$PSScriptRoot\" + $file.Name) ` -CentralAdminUrl $centralAdminUrl ` -GlobalAdminAccount $GlobalAdminAccount } @@ -665,7 +666,7 @@ function Start-O365ConfigurationExtract $app = Get-PnpApp -Identity $file.Title -ErrorAction SilentlyContinue $partialContent = Export-TargetResource -Identity $app.Title ` - -Path ("`$(`$ConfigurationData.NonNodeData.AppsLocation)" + $file.Name) ` + -Path ("`$PSScriptRoot\" + $file.Name) ` -CentralAdminUrl $centralAdminUrl ` -GlobalAdminAccount $GlobalAdminAccount } @@ -1163,10 +1164,6 @@ function Start-O365ConfigurationExtract #region Copy Downloaded files back into output folder if ($filesToDownload.Count -gt 0) { - Add-ConfigurationDataEntry -Node "NonNodeData" ` - -Key "AppsLocation" ` - -Value $OutputDSCPath ` - -Description "Location of the .app and .sppkg packages" foreach ($fileToCopy in $filesToDownload) { $filePath = Join-Path $env:Temp $fileToCopy.Name -Resolve From 16f20b4cd634c3d66ab284039e9eab582a3e86f9 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 11 Jul 2019 18:44:55 -0400 Subject: [PATCH 7/8] Lean Metadata --- Modules/Office365DSC/Office365DSC.psd1 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Modules/Office365DSC/Office365DSC.psd1 b/Modules/Office365DSC/Office365DSC.psd1 index 49622b9c85..330cc05799 100644 --- a/Modules/Office365DSC/Office365DSC.psd1 +++ b/Modules/Office365DSC/Office365DSC.psd1 @@ -78,10 +78,7 @@ #FunctionsToExport = @() # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. - CmdletsToExport = 'Test-Office365DSCParameterState', 'Export-O365Configuration', - 'Get-TimeZoneNameFromID', 'Get-TimeZoneIDFromName', 'Get-LocaleIDFromName', - 'Get-LocaleNameFromID', 'Show-O365GUI', 'Start-O365ConfigurationExtract', - 'New-Office365DSCLogEntry' + CmdletsToExport = 'Export-O365Configuration' # Variables to export from this module # VariablesToExport = @() From 5c20ec3afac8bdab27a4e94588ab41d869e031d7 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 11 Jul 2019 20:07:41 -0400 Subject: [PATCH 8/8] Fixed errors in Test Harness mocks --- .../Unit/Office365DSC/Office365DSC.EXOAntiPhishPolicy.Tests.ps1 | 2 +- Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishRule.Tests.ps1 | 2 +- .../Office365DSC/Office365DSC.EXOAtpPolicyForO365.Tests.ps1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishPolicy.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishPolicy.Tests.ps1 index a14fd3dff3..540a7dc7a8 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishPolicy.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishPolicy.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName MSCloudLogin -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishRule.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishRule.Tests.ps1 index 0c4c6809b6..7d79f2766d 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishRule.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOAntiPhishRule.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName MSCloudLogin -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { } diff --git a/Tests/Unit/Office365DSC/Office365DSC.EXOAtpPolicyForO365.Tests.ps1 b/Tests/Unit/Office365DSC/Office365DSC.EXOAtpPolicyForO365.Tests.ps1 index 8fff64624b..3812176b0d 100644 --- a/Tests/Unit/Office365DSC/Office365DSC.EXOAtpPolicyForO365.Tests.ps1 +++ b/Tests/Unit/Office365DSC/Office365DSC.EXOAtpPolicyForO365.Tests.ps1 @@ -24,7 +24,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } - Mock -CommandName MSCloudLogin -MockWith { + Mock -CommandName Test-MSCloudLogin -MockWith { }