fix: formatting

This commit is contained in:
DrIOS
2025-04-19 19:51:38 -05:00
parent 445c962af0
commit 00c06f7d25

View File

@@ -3,22 +3,21 @@ function Connect-M365Suite {
[CmdletBinding()] [CmdletBinding()]
param ( param (
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[string]$TenantAdminUrl, [string]
$TenantAdminUrl,
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[CISAuthenticationParameters]$AuthParams, [CISAuthenticationParameters]
$AuthParams,
[Parameter(Mandatory)] [Parameter(Mandatory)]
[string[]]$RequiredConnections, [string[]]
$RequiredConnections,
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[switch]$SkipConfirmation [switch]
$SkipConfirmation
) )
$VerbosePreference = if ($SkipConfirmation) { 'SilentlyContinue' } else { 'Continue' } $VerbosePreference = if ($SkipConfirmation) { 'SilentlyContinue' } else { 'Continue' }
$tenantInfo = @() $tenantInfo = @()
$connectedServices = @() $connectedServices = @()
try { try {
if ($RequiredConnections -contains 'Microsoft Graph' -or $RequiredConnections -contains 'EXO | Microsoft Graph') { if ($RequiredConnections -contains 'Microsoft Graph' -or $RequiredConnections -contains 'EXO | Microsoft Graph') {
try { try {
@@ -42,7 +41,6 @@ function Connect-M365Suite {
throw "Failed to connect to Microsoft Graph: $($_.Exception.Message)" throw "Failed to connect to Microsoft Graph: $($_.Exception.Message)"
} }
} }
if ($RequiredConnections -contains 'EXO' -or $RequiredConnections -contains 'AzureAD | EXO' -or $RequiredConnections -contains 'Microsoft Teams | EXO' -or $RequiredConnections -contains 'EXO | Microsoft Graph') { if ($RequiredConnections -contains 'EXO' -or $RequiredConnections -contains 'AzureAD | EXO' -or $RequiredConnections -contains 'Microsoft Teams | EXO' -or $RequiredConnections -contains 'EXO | Microsoft Graph') {
try { try {
Write-Verbose 'Connecting to Exchange Online...' Write-Verbose 'Connecting to Exchange Online...'
@@ -65,7 +63,6 @@ function Connect-M365Suite {
throw "Failed to connect to Exchange Online: $($_.Exception.Message)" throw "Failed to connect to Exchange Online: $($_.Exception.Message)"
} }
} }
if ($RequiredConnections -contains 'SPO') { if ($RequiredConnections -contains 'SPO') {
try { try {
Write-Verbose 'Connecting to SharePoint Online...' Write-Verbose 'Connecting to SharePoint Online...'
@@ -79,7 +76,8 @@ function Connect-M365Suite {
(Get-PnPSite).Url (Get-PnPSite).Url
} }
else { else {
# Supress output from Get-SPOSite for powerautomate to avoid errors # Returns the first site base URL from the tenant
# Suppress output from Get-SPOSite for powerautomate to avoid errors
[void]($sites = Get-SPOSite -Limit All) [void]($sites = Get-SPOSite -Limit All)
# Get the URL from the first site collection # Get the URL from the first site collection
$url = $sites[0].Url $url = $sites[0].Url
@@ -99,7 +97,6 @@ function Connect-M365Suite {
throw "Failed to connect to SharePoint Online: $($_.Exception.Message)" throw "Failed to connect to SharePoint Online: $($_.Exception.Message)"
} }
} }
if ($RequiredConnections -contains 'Microsoft Teams' -or $RequiredConnections -contains 'Microsoft Teams | EXO') { if ($RequiredConnections -contains 'Microsoft Teams' -or $RequiredConnections -contains 'Microsoft Teams | EXO') {
try { try {
Write-Verbose 'Connecting to Microsoft Teams...' Write-Verbose 'Connecting to Microsoft Teams...'
@@ -122,14 +119,13 @@ function Connect-M365Suite {
throw "Failed to connect to Microsoft Teams: $($_.Exception.Message)" throw "Failed to connect to Microsoft Teams: $($_.Exception.Message)"
} }
} }
if (-not $SkipConfirmation) { if (-not $SkipConfirmation) {
Write-Verbose 'Connected to the following tenants:' Write-Verbose 'Connected to the following tenants:'
foreach ($tenant in $tenantInfo) { foreach ($tenant in $tenantInfo) {
Write-Verbose "Service: $($tenant.Service) | Tenant: $($tenant.TenantName)" Write-Verbose "Service: $($tenant.Service) | Tenant: $($tenant.TenantName)"
} }
if ($script:PnpAuth) { if ($script:PnpAuth) {
Write-Warning "`n!!!!!!!!!!!!Important!!!!!!!!!!!!!!`nIf you use the auth object, you will need to kill the current session before subsequent runs`nas the PNP.Powershell module has conflicts with MgGraph!`nIf Invoke-M365SecurityAudit is invoked in a runspace, you can circumvent the issue!`n!!!!!!!!!!!!Important!!!!!!!!!!!!!!" Write-Warning "`n!!!!!!!!!!!!Important!!!!!!!!!!!!!!`nIf you use the auth object, you may need to kill the current session before subsequent runs`nas the PNP.Powershell module has conflicts with MgGraph authentication modules!`n!!!!!!!!!!!!Important!!!!!!!!!!!!!!"
} }
$confirmation = Read-Host "Do you want to proceed with these connections? (Y/N)" $confirmation = Read-Host "Do you want to proceed with these connections? (Y/N)"
if ($confirmation -notLike 'Y') { if ($confirmation -notLike 'Y') {