2019-11-01 15:04:32 +05:30
|
|
|
|
|
|
|
|
|
|
Param
|
|
|
|
|
|
(
|
|
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
|
|
|
|
[switch]$Disconnect,
|
2021-01-21 21:01:56 +05:30
|
|
|
|
[ValidateSet('AzureAD','MSOnline','ExchangeOnline','SharePoint','SharePointPnP','SecAndCompCenter','Skype','Teams')]
|
|
|
|
|
|
[string[]]$Services=("AzureAD","MSOnline","ExchangeOnline",'SharePoint','SharePointPnP','SecAndCompCenter','Skype','Teams'),
|
2019-11-01 15:04:32 +05:30
|
|
|
|
[string]$SharePointHostName,
|
|
|
|
|
|
[Switch]$MFA,
|
|
|
|
|
|
[string]$UserName,
|
|
|
|
|
|
[string]$Password
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
#Disconnecting Sessions
|
|
|
|
|
|
if($Disconnect.IsPresent)
|
|
|
|
|
|
{
|
|
|
|
|
|
#Disconnect Exchange Online,Skype and Security & Compliance center session
|
|
|
|
|
|
Get-PSSession | Remove-PSSession
|
|
|
|
|
|
#Disconnect Teams connection
|
|
|
|
|
|
Disconnect-MicrosoftTeams
|
|
|
|
|
|
#Disconnect SharePoint connection
|
|
|
|
|
|
Disconnect-SPOService
|
|
|
|
|
|
Write-Host All sessions in the current window has been removed. -ForegroundColor Yellow
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if(($UserName -ne "") -and ($Password -ne ""))
|
|
|
|
|
|
{
|
|
|
|
|
|
$SecuredPassword = ConvertTo-SecureString -AsPlainText $Password -Force
|
|
|
|
|
|
$Credential = New-Object System.Management.Automation.PSCredential $UserName,$SecuredPassword
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#Getting credential for non-MFA account
|
|
|
|
|
|
elseif(!($MFA.IsPresent))
|
|
|
|
|
|
{
|
|
|
|
|
|
$Credential=Get-Credential -Credential $null
|
|
|
|
|
|
}
|
|
|
|
|
|
$ConnectedServices=""
|
2021-01-21 21:01:56 +05:30
|
|
|
|
if($Services.Length -eq 8)
|
2019-11-01 15:04:32 +05:30
|
|
|
|
{
|
|
|
|
|
|
$RequiredServices=$Services
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$RequiredServices=$PSBoundParameters.Services
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#Loop through each required services
|
|
|
|
|
|
Foreach($Service in $RequiredServices)
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host Checking connection to $Service...
|
|
|
|
|
|
Switch ($Service)
|
|
|
|
|
|
{
|
|
|
|
|
|
#Module and Connection settings for Exchange Online module
|
|
|
|
|
|
ExchangeOnline
|
|
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
$Module=Get-InstalledModule -Name ExchangeOnlineManagement -MinimumVersion 2.0.3
|
|
|
|
|
|
if($Module.count -eq 0)
|
2019-11-01 15:04:32 +05:30
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
Write-Host Required Exchange Online'(EXO V2)' module is not available -ForegroundColor yellow
|
|
|
|
|
|
$Confirm= Read-Host Are you sure you want to install module? [Y] Yes [N] No
|
|
|
|
|
|
if($Confirm -match "[yY]")
|
2019-11-01 15:04:32 +05:30
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
Install-Module ExchangeOnlineManagement
|
|
|
|
|
|
Import-Module ExchangeOnlineManagement
|
2019-11-01 15:04:32 +05:30
|
|
|
|
}
|
2021-01-21 21:01:56 +05:30
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host EXO V2 module is required to connect Exchange Online.Please install module using Install-Module ExchangeOnlineManagement cmdlet.
|
|
|
|
|
|
}
|
|
|
|
|
|
Continue
|
|
|
|
|
|
}
|
|
|
|
|
|
if($mfa.IsPresent)
|
|
|
|
|
|
{
|
|
|
|
|
|
Connect-ExchangeOnline
|
2019-11-01 15:04:32 +05:30
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
Connect-ExchangeOnline -Credential $Credential
|
2019-11-01 15:04:32 +05:30
|
|
|
|
}
|
2021-01-21 21:01:56 +05:30
|
|
|
|
If((Get-EXOMailbox -ResultSize 1) -ne $null)
|
2019-11-01 15:04:32 +05:30
|
|
|
|
{
|
|
|
|
|
|
if($ConnectedServices -ne "")
|
|
|
|
|
|
{
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+","
|
2021-01-21 21:01:56 +05:30
|
|
|
|
}
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+" Exchange Online"
|
2019-11-01 15:04:32 +05:30
|
|
|
|
}
|
2021-01-21 21:01:56 +05:30
|
|
|
|
}
|
2019-11-01 15:04:32 +05:30
|
|
|
|
|
2021-01-21 21:01:56 +05:30
|
|
|
|
#Module and Connection settings for AzureAD V1 (MSOnline module)
|
|
|
|
|
|
MSOnline
|
2019-11-01 15:04:32 +05:30
|
|
|
|
{
|
|
|
|
|
|
$Module=Get-Module -Name MSOnline -ListAvailable
|
|
|
|
|
|
if($Module.count -eq 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host MSOnline module is not available -ForegroundColor yellow
|
|
|
|
|
|
$Confirm= Read-Host Are you sure you want to install module? [Y] Yes [N] No
|
|
|
|
|
|
if($Confirm -match "[yY]")
|
|
|
|
|
|
{
|
|
|
|
|
|
Install-Module MSOnline
|
2021-01-21 21:01:56 +05:30
|
|
|
|
Import-Module MSOnline
|
2019-11-01 15:04:32 +05:30
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host MSOnline module is required to connect AzureAD.Please install module using Install-Module MSOnline cmdlet.
|
|
|
|
|
|
}
|
|
|
|
|
|
Continue
|
|
|
|
|
|
}
|
|
|
|
|
|
if($mfa.IsPresent)
|
|
|
|
|
|
{
|
|
|
|
|
|
Connect-MsolService
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Connect-MsolService -Credential $Credential
|
|
|
|
|
|
}
|
|
|
|
|
|
If((Get-MsolUser -MaxResults 1) -ne $null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if($ConnectedServices -ne "")
|
|
|
|
|
|
{
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+","
|
|
|
|
|
|
}
|
2021-01-21 21:01:56 +05:30
|
|
|
|
$ConnectedServices=$ConnectedServices+" MSOnline"
|
|
|
|
|
|
}
|
|
|
|
|
|
if(($RequiredServices -contains "SharePoint") -eq "true")
|
2019-11-01 15:04:32 +05:30
|
|
|
|
{
|
|
|
|
|
|
$SharePointHostName=((Get-MsolDomain) | where {$_.IsInitial -eq "True"} ).name -split ".onmicrosoft.com"
|
|
|
|
|
|
$SharePointHostName=($SharePointHostName).trim()
|
|
|
|
|
|
}
|
2021-01-21 21:01:56 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Module and Connection settings for AzureAD V2 (AzureAD module)
|
|
|
|
|
|
AzureAD
|
|
|
|
|
|
{
|
|
|
|
|
|
$Module=Get-Module -Name AzureAD -ListAvailable
|
|
|
|
|
|
if($Module.count -eq 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host AzureAD module is not available -ForegroundColor yellow
|
|
|
|
|
|
$Confirm= Read-Host Are you sure you want to install module? [Y] Yes [N] No
|
|
|
|
|
|
if($Confirm -match "[yY]")
|
|
|
|
|
|
{
|
|
|
|
|
|
Install-Module AzureAD
|
|
|
|
|
|
Import-Module AzureAD
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host AzureAD module is required to connect AzureAD.Please install module using Install-Module AzureAD cmdlet.
|
|
|
|
|
|
}
|
|
|
|
|
|
Continue
|
|
|
|
|
|
}
|
|
|
|
|
|
if($mfa.IsPresent)
|
|
|
|
|
|
{
|
|
|
|
|
|
Connect-AzureAD
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Connect-AzureAD -Credential $Credential
|
|
|
|
|
|
}
|
|
|
|
|
|
If((Get-AzureADUser -Top 1) -ne $null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if($ConnectedServices -ne "")
|
|
|
|
|
|
{
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+","
|
|
|
|
|
|
}
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+" AzureAD"
|
|
|
|
|
|
|
2019-11-01 15:04:32 +05:30
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#Module and Connection settings for SharePoint Online module
|
|
|
|
|
|
SharePoint
|
|
|
|
|
|
{
|
|
|
|
|
|
$Module=Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable
|
|
|
|
|
|
if($Module.count -eq 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host SharePoint Online PowerShell module is not available -ForegroundColor yellow
|
|
|
|
|
|
$Confirm= Read-Host Are you sure you want to install module? [Y] Yes [N] No
|
|
|
|
|
|
if($Confirm -match "[yY]")
|
|
|
|
|
|
{
|
|
|
|
|
|
Install-Module Microsoft.Online.SharePoint.PowerShell
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host SharePoint Online PowerShell module is required.Please install module using Install-Module Microsoft.Online.SharePoint.PowerShell cmdlet.
|
|
|
|
|
|
Continue
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!($PSBoundParameters['SharePointHostName']) -and ([string]$SharePointHostName -eq "") )
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host SharePoint organization name is required.`nEg: Contoso for admin@Contoso.Onmicrosoft.com -ForegroundColor Yellow
|
|
|
|
|
|
$SharePointHostName= Read-Host "Please enter SharePoint organization name"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if($MFA.IsPresent)
|
|
|
|
|
|
{
|
|
|
|
|
|
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
|
|
|
|
|
|
Connect-SPOService -Url https://$SharePointHostName-admin.sharepoint.com
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
|
|
|
|
|
|
Connect-SPOService -Url https://$SharePointHostName-admin.sharepoint.com -credential $credential
|
|
|
|
|
|
}
|
|
|
|
|
|
if((Get-SPOTenant) -ne $null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if($ConnectedServices -ne "")
|
|
|
|
|
|
{
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+","
|
|
|
|
|
|
}
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+"SharePoint Online"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-21 21:01:56 +05:30
|
|
|
|
#Module and Connection settings for Sharepoint PnP module
|
|
|
|
|
|
SharePointPnP
|
|
|
|
|
|
{
|
|
|
|
|
|
$Module=Get-InstalledModule -Name SharePointPnPPowerShellOnline
|
|
|
|
|
|
if($Module.count -eq 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host SharePoint PnP module module is not available -ForegroundColor yellow
|
|
|
|
|
|
$Confirm= Read-Host Are you sure you want to install module? [Y] Yes [N] No
|
|
|
|
|
|
if($Confirm -match "[yY]")
|
|
|
|
|
|
{
|
|
|
|
|
|
Install-Module -Name SharePointPnPPowerShellOnline -AllowClobber
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host SharePoint Pnp module is required.Please install module using Install-Module SharePointPnPPowerShellOnline cmdlet.
|
|
|
|
|
|
}
|
|
|
|
|
|
Continue
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!($PSBoundParameters['SharePointHostName']) -and ([string]$SharePointHostName -eq "") )
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host SharePoint organization name is required.`nEg: Contoso for admin@Contoso.com -ForegroundColor Yellow
|
|
|
|
|
|
$SharePointHostName= Read-Host "Please enter SharePoint organization name"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if($MFA.IsPresent)
|
|
|
|
|
|
{
|
|
|
|
|
|
Import-Module SharepointpnpPowerShellOnline -DisableNameChecking
|
|
|
|
|
|
Connect-PnPOnline -Url https://$SharePointHostName.sharepoint.com -UseWebLogin -WarningAction Ignore
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Import-Module SharepointpnpPowerShellOnline -DisableNameChecking
|
|
|
|
|
|
Connect-PnPOnline -Url https://$SharePointHostName.sharepoint.com -credential $credential -WarningAction Ignore
|
|
|
|
|
|
}
|
|
|
|
|
|
If ($? -eq $true)
|
|
|
|
|
|
{
|
|
|
|
|
|
if($ConnectedServices -ne "")
|
|
|
|
|
|
{
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+","
|
|
|
|
|
|
}
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+"SharePoint PnP"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-11-01 15:04:32 +05:30
|
|
|
|
#Module and Connection settings for Skype for Business Online module
|
|
|
|
|
|
Skype
|
|
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
$Module=Get-InstalledModule -Name MicrosoftTeams -MinimumVersion 1.1.6
|
2019-11-01 15:04:32 +05:30
|
|
|
|
if($Module.count -eq 0)
|
|
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
Write-Host Required MicrosoftTeams module is not available -ForegroundColor yellow
|
|
|
|
|
|
$Confirm= Read-Host Are you sure you want to install module? [Y] Yes [N] No
|
|
|
|
|
|
if($Confirm -match "[yY]")
|
|
|
|
|
|
{
|
|
|
|
|
|
Install-Module MicrosoftTeams -AllowClobber
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host MicrosoftTeams module is required.Please install module using Install-Module MicrosoftTeams cmdlet.
|
|
|
|
|
|
}
|
2019-11-01 15:04:32 +05:30
|
|
|
|
Continue
|
|
|
|
|
|
}
|
|
|
|
|
|
if($MFA.IsPresent)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sfbSession = New-CsOnlineSession
|
|
|
|
|
|
Import-PSSession $sfbSession -AllowClobber | Out-Null
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$sfbSession = New-CsOnlineSession -Credential $Credential
|
|
|
|
|
|
Import-PSSession $sfbSession -AllowClobber -WarningAction SilentlyContinue | Out-Null
|
|
|
|
|
|
}
|
|
|
|
|
|
#Check for Skype connectivity
|
|
|
|
|
|
If ((Get-PSSession | Where-Object { $_.ConfigurationName -like "Microsoft.PowerShell" }) -ne $null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if($ConnectedServices -ne "")
|
|
|
|
|
|
{
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+","
|
|
|
|
|
|
}
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+"Skype"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#Module and Connection settings for Security & Compliance center
|
|
|
|
|
|
SecAndCompCenter
|
|
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
$Module=Get-InstalledModule -Name ExchangeOnlineManagement -MinimumVersion 2.0.3
|
|
|
|
|
|
if($Module.count -eq 0)
|
2019-11-01 15:04:32 +05:30
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
Write-Host Exchange Online'(EXO V2)' module is not available -ForegroundColor yellow
|
|
|
|
|
|
$Confirm= Read-Host Are you sure you want to install module? [Y] Yes [N] No
|
|
|
|
|
|
if($Confirm -match "[yY]")
|
2019-11-01 15:04:32 +05:30
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
Install-Module ExchangeOnlineManagement
|
|
|
|
|
|
Import-Module ExchangeOnlineManagement
|
2019-11-01 15:04:32 +05:30
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
Write-Host EXO V2 module is required to connect Security and Compliance PowerShell.Please install module using Install-Module ExchangeOnlineManagement cmdlet.
|
|
|
|
|
|
}
|
|
|
|
|
|
Continue
|
|
|
|
|
|
}
|
|
|
|
|
|
if($mfa.IsPresent)
|
|
|
|
|
|
{
|
|
|
|
|
|
Connect-IPPSSession -WarningAction SilentlyContinue
|
2019-11-01 15:04:32 +05:30
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
Connect-IPPSSession -Credential $Credential -WarningAction SilentlyContinue
|
2019-11-01 15:04:32 +05:30
|
|
|
|
}
|
2021-01-21 21:01:56 +05:30
|
|
|
|
$Result=Get-RetentionCompliancePolicy
|
|
|
|
|
|
If(($?) -eq $true)
|
2019-11-01 15:04:32 +05:30
|
|
|
|
{
|
|
|
|
|
|
if($ConnectedServices -ne "")
|
|
|
|
|
|
{
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+","
|
|
|
|
|
|
}
|
2021-01-21 21:01:56 +05:30
|
|
|
|
$ConnectedServices=$ConnectedServices+" Security & Compliance Center"
|
2019-11-01 15:04:32 +05:30
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-01-21 21:01:56 +05:30
|
|
|
|
|
2019-11-01 15:04:32 +05:30
|
|
|
|
#Module and Connection settings for Teams Online module
|
|
|
|
|
|
Teams
|
|
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
$Module=Get-InstalledModule -Name MicrosoftTeams -MinimumVersion 1.1.6
|
2019-11-01 15:04:32 +05:30
|
|
|
|
if($Module.count -eq 0)
|
|
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
Write-Host Required MicrosoftTeams module is not available -ForegroundColor yellow
|
2019-11-01 15:04:32 +05:30
|
|
|
|
$Confirm= Read-Host Are you sure you want to install module? [Y] Yes [N] No
|
|
|
|
|
|
if($Confirm -match "[yY]")
|
|
|
|
|
|
{
|
2021-01-21 21:01:56 +05:30
|
|
|
|
Install-Module MicrosoftTeams -AllowClobber
|
2019-11-01 15:04:32 +05:30
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Write-Host MicrosoftTeams module is required.Please install module using Install-Module MicrosoftTeams cmdlet.
|
|
|
|
|
|
}
|
|
|
|
|
|
Continue
|
|
|
|
|
|
}
|
|
|
|
|
|
if($mfa.IsPresent)
|
|
|
|
|
|
{
|
|
|
|
|
|
$Team=Connect-MicrosoftTeams
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$Team=Connect-MicrosoftTeams -Credential $Credential
|
|
|
|
|
|
}
|
|
|
|
|
|
#Check for Teams connectivity
|
|
|
|
|
|
If($Team -ne $null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if($ConnectedServices -ne "")
|
|
|
|
|
|
{
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+","
|
|
|
|
|
|
}
|
|
|
|
|
|
$ConnectedServices=$ConnectedServices+"Teams"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if($ConnectedServices -eq "")
|
|
|
|
|
|
{
|
|
|
|
|
|
$ConnectedServices="-"
|
|
|
|
|
|
}
|
|
|
|
|
|
Write-Host `n`nConnected Services $ConnectedServices -ForegroundColor DarkYellow
|
|
|
|
|
|
}
|