Advertisement
Guest User

Untitled

a guest
May 21st, 2019
1,222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Connect-Office365 {
  2.  
  3.     <#
  4.     .SYNOPSIS
  5.     -Taylor Lee
  6.     Modified 05172019
  7.  
  8.     .DESCRIPTION
  9.     Connect to all Office 365 Modules or just those chosen using the provided parameters
  10.  
  11.     .Example
  12.     Connect-Office365 -acctName name@bigcompany.com -domainHost bigcompany -all
  13.  
  14.     Connects to all included office 365 modules for this Function
  15.  
  16.     .Example
  17.     Connect-Office365 -acctName name@bigcompany.com -skype
  18.  
  19.     Connects to skype and includes it mandatory parameters
  20.  
  21.     .Example
  22.     Connect-Office365 -domainhost bigcompany -SharepointOnline
  23.  
  24.     Connects to skype and includes it mandatory parameters
  25.  
  26.     .Example
  27.     Connect-Office365 -AzureAD
  28.  
  29.     Connects to a specific module using the available AzureAD parameter
  30.  
  31.     .Example
  32.     Connect-Office365 -AzureAD -Teams
  33.  
  34.     Connects to multiple specified modules
  35.  
  36.     .Notes
  37.     #Sharepoint Online Module
  38.     The SharePoint Online Management Shell is a Windows PowerShell module that you can use to manage SharePoint Online users, sites, and site collections.
  39.     Sharepoint Online Module https://www.microsoft.com/en-us/download/details.aspx?id=35588
  40.  
  41.     #Azure AD Module
  42.     Windows Azure AD tenant-based administrative tasks such as user management, domain management and for configuring single sign-on
  43.     Install-Module AzureAD
  44.  
  45.     #Exchange Online Module
  46.     Exchange Online PowerShell allows you to manage your Exchange Online settings from the command line.
  47.     Download the Exchange Online Module from the Hybrid section of Office 365 Exchange Admin Center
  48.  
  49.     #Security and Compliance Module
  50.     Office 365 Security & Compliance Center PowerShell allows you to manage your Office 365 Security & Compliance Center settings from the command line.
  51.     Download the Exchange Online Module from the Hybrid section of Office 365 Exchange Admin Center
  52.  
  53.     #Skype For Business Module
  54.     Skype For Business Module allows managing Skype for Business settings from the Command Line.
  55.     Download and install Skype for Business Module https://www.microsoft.com/en-us/download/details.aspx?id=39366
  56.     If bug still exists, Visual C++ 2017 x64 14.10.25008 is needed to work with this module.
  57.  
  58.     #Microsoft Teams Module
  59.     Microsoft Teams Module Module allows managing Microsoft Teams settings from the Command Line.
  60.     Install-module MicrosoftTeams
  61.  
  62.     #Azure AZ Module
  63.     Azure Az Module Module allows managing Azure settings, subscriptions, VM, Resource groups, and more from the Command Line.
  64.     Replaces Azure RM
  65.     Install-Module -Name Az
  66.     #>
  67.  
  68.     [CmdletBinding(SupportsShouldProcess)]
  69.  
  70.     Param (
  71.         [Parameter(Mandatory = $true, ParameterSetName = "All")][Parameter(Mandatory = $true, ParameterSetName = "Skype")]$AcctName,
  72.         [Parameter(Mandatory = $true, ParameterSetName = "All")][Parameter(Mandatory = $true, ParameterSetName = "Sharepoint")]$DomainHost,
  73.         [Parameter(Mandatory = $true, ParameterSetName = "All")][Switch] $All,
  74.         [Parameter(Mandatory = $true, ParameterSetName = "AzureAD")][Switch] $AzureAD,
  75.         [Parameter(Mandatory = $true, ParameterSetName = "Sharepoint")][Switch] $SharepointOnline,
  76.         [Parameter(Mandatory = $true, ParameterSetName = "ExchangeOnline")][Switch] $ExchangeOnline,
  77.         [Parameter(Mandatory = $true, ParameterSetName = "SecurityandCompliance")][Switch] $SecurityandCompliance,
  78.         [Parameter(Mandatory = $true, ParameterSetName = "Skype")][Switch] $Skype,
  79.         [Parameter(Mandatory = $true, ParameterSetName = "Teams")][Switch] $Teams,
  80.         [Parameter(Mandatory = $true, ParameterSetName = "Az")][Switch] $Az
  81.     )
  82.  
  83.     if ($SharepointOnline) {
  84.         #Sharepoint Online Module
  85.         Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
  86.         Write-Host "Connecting to SharePoint Online" -backgroundcolor black -foregroundcolor green
  87.         Connect-SPOService -Url https://$DomainHost-admin.sharepoint.com
  88.     }
  89.  
  90.     if ($AzureAD) {
  91.         #Azure AD Module
  92.         Write-Host "Connecting to other Azure AD Services" -backgroundcolor black -foregroundcolor green
  93.         Connect-AzureAD
  94.     }
  95.  
  96.     if ($ExchangeOnline) {
  97.         #Exchange Online Module
  98.         Write-Host "Connecting to Exchange Online Services" -backgroundcolor black -foregroundcolor green
  99.         $CreateEXOPSSession = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -Last 1).DirectoryName
  100.         . "$CreateEXOPSSession\CreateExoPSSession.ps1"
  101.         Connect-EXOPSSession
  102.     }
  103.  
  104.     if ($SecurityandCompliance) {
  105.         #Security and Compliance Module
  106.         Write-Host "Connecting to Exchange Online Protection and Security (aka Security and Compliance)" -backgroundcolor black -foregroundcolor green
  107.         Connect-ippssession
  108.     }
  109.  
  110.     if ($Skype) {
  111.         #Skype For Business Module
  112.         Import-Module SkypeOnlineConnector
  113.         Write-Host "Connecting to Skype for Business Online" -backgroundcolor black -foregroundcolor green
  114.         $sfboSession = New-CsOnlineSession -UserName $AcctName
  115.         Import-PSSession $sfboSession
  116.     }
  117.  
  118.     if ($Teams) {
  119.         #Microsoft Teams Module
  120.         Write-Host "Connecting to Microsoft Teams" -backgroundcolor black -foregroundcolor green
  121.         Connect-MicrosoftTeams
  122.        
  123.         $SkypeRequired = Read-Host "Did you import the additionaly required skype module? Yes or No"
  124.            
  125.         if ($SkypeRequired -eq 'No') {
  126.             #Skype For Business Module
  127.             Import-Module SkypeOnlineConnector
  128.             Write-Host "Connecting to Skype for Business Online" -backgroundcolor black -foregroundcolor green
  129.             $sfboSession = New-CsOnlineSession -UserName $AcctName
  130.             Import-PSSession $sfboSession
  131.            
  132.         }
  133.     }
  134.  
  135.     if ($Az) {
  136.         #Azure Az Module
  137.         Write-Host "Connecting to Azure Az Module" -backgroundcolor black -foregroundcolor green
  138.         Connect-AzAccount
  139.     }
  140.  
  141.     if ($All) {
  142.         #Sharepoint Online Module
  143.         Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
  144.         Write-Host "Connecting to SharePoint Online" -backgroundcolor black -foregroundcolor green
  145.         Connect-SPOService -Url https://$DomainHost-admin.sharepoint.com
  146.  
  147.         #Azure AD Module
  148.         Write-Host "Connecting to other Azure AD Services" -backgroundcolor black -foregroundcolor green
  149.         Connect-AzureAD
  150.  
  151.         #Exchange Online Module
  152.         Write-Host "Connecting to Exchange Online Services" -backgroundcolor black -foregroundcolor green
  153.         $CreateEXOPSSession = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -Last 1).DirectoryName
  154.         . "$CreateEXOPSSession\CreateExoPSSession.ps1"
  155.         Connect-EXOPSSession
  156.  
  157.         #Security and Compliance Module
  158.         Write-Host "Connecting to Exchange Online Protection and Security (aka Security and Compliance)" -backgroundcolor black -foregroundcolor green
  159.         Connect-ippssession
  160.  
  161.         #Skype For Business Module
  162.         Import-Module SkypeOnlineConnector
  163.         Write-Host "Connecting to Skype for Business Online" -backgroundcolor black -foregroundcolor green
  164.         $sfboSession = New-CsOnlineSession -UserName $AcctName
  165.         Import-PSSession $sfboSession
  166.  
  167.         #Microsoft Teams Module
  168.         Write-Host "Connecting to Microsoft Teams" -backgroundcolor black -foregroundcolor green
  169.         Connect-MicrosoftTeams
  170.  
  171.         #Azure Az Module
  172.         Write-Host "Connecting to Azure Az Module" -backgroundcolor black -foregroundcolor green
  173.         Connect-AzAccount
  174.     }
  175.  
  176.     Write-Host "Going to import modules with verbose switch so all commands are available" -backgroundcolor black -foregroundcolor green
  177.     pause
  178.     get-module | import-module -verbose
  179.     Clear-Host
  180.     Get-Command | Out-GridView
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement