Advertisement
Guest User

Untitled

a guest
May 21st, 2019
656
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,
  39. and site collections.
  40.     Sharepoint Online Module https://www.microsoft.com/en-us/download/details.aspx?id=35588
  41.  
  42.     #Azure AD Module
  43.     Windows Azure AD tenant-based administrative tasks such as user management, domain management and for configuring single sign-on
  44.     Install-Module AzureAD
  45.  
  46.     #Exchange Online Module
  47.     Exchange Online PowerShell allows you to manage your Exchange Online settings from the command line.
  48.     Download the Exchange Online Module from the Hybrid section of Office 365 Exchange Admin Center
  49.  
  50.     #Security and Compliance Module
  51.     Office 365 Security & Compliance Center PowerShell allows you to manage your Office 365 Security & Compliance Center settings from the command line.
  52.     Download the Exchange Online Module from the Hybrid section of Office 365 Exchange Admin Center
  53.  
  54.     #Skype For Business Module
  55.     Skype For Business Module allows managing Skype for Business settings from the Command Line.
  56.     Download and install Skype for Business Module https://www.microsoft.com/en-us/download/details.aspx?id=39366
  57.     If bug still exists, Visual C++ 2017 x64 14.10.25008 is needed to work with this module.
  58.  
  59.     #Microsoft Teams Module
  60.     Microsoft Teams Module Module allows managing Microsoft Teams settings from the Command Line.
  61.     Install-module MicrosoftTeams
  62.  
  63.     #Azure AZ Module
  64.     Azure Az Module Module allows managing Azure settings, subscriptions, VM, Resource groups, and more from the Command Line.
  65.     Replaces Azure RM
  66.     Install-Module -Name Az
  67.     #>
  68.  
  69.     [CmdletBinding(SupportsShouldProcess)]
  70.  
  71.     Param (
  72.         [Parameter(Mandatory = $true, ParameterSetName = "All")][Parameter(Mandatory = $true, ParameterSetName = "Skype")]$AcctName,
  73.         [Parameter(Mandatory = $true, ParameterSetName = "All")][Parameter(Mandatory = $true, ParameterSetName = "Sharepoint")]$DomainHost,
  74.         [Parameter(Mandatory = $true, ParameterSetName = "All")][Switch] $All,
  75.         [Parameter(Mandatory = $true, ParameterSetName = "AzureAD")][Switch] $AzureAD,
  76.         [Parameter(Mandatory = $true, ParameterSetName = "Sharepoint")][Switch] $SharepointOnline,
  77.         [Parameter(Mandatory = $true, ParameterSetName = "ExchangeOnline")][Switch] $ExchangeOnline,
  78.         [Parameter(Mandatory = $true, ParameterSetName = "SecurityandCompliance")][Switch] $SecurityandCompliance,
  79.         [Parameter(Mandatory = $true, ParameterSetName = "Skype")][Switch] $Skype,
  80.         [Parameter(Mandatory = $true, ParameterSetName = "Teams")][Switch] $Teams,
  81.         [Parameter(Mandatory = $true, ParameterSetName = "Az")][Switch] $Az
  82.     )
  83.  
  84.     if ($SharepointOnline) {
  85.         #Sharepoint Online Module
  86.         Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
  87.         Write-Host "Connecting to SharePoint Online" -backgroundcolor black -foregroundcolor green
  88.         Connect-SPOService -Url https://$DomainHost-admin.sharepoint.com
  89.     }
  90.  
  91.     if ($AzureAD) {
  92.         #Azure AD Module
  93.         Write-Host "Connecting to other Azure AD Services" -backgroundcolor black -foregroundcolor green
  94.         Connect-AzureAD
  95.     }
  96.  
  97.     if ($ExchangeOnline) {
  98.         #Exchange Online Module
  99.         Write-Host "Connecting to Exchange Online Services" -backgroundcolor black -foregroundcolor green
  100.         $CreateEXOPSSession = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -ErrorAction SilentlyContinue -Force | Select -Last 1).DirectoryName
  101.         . "$CreateEXOPSSession\CreateExoPSSession.ps1"
  102.         Connect-EXOPSSession
  103.     }
  104.  
  105.     if ($SecurityandCompliance) {
  106.         #Security and Compliance Module
  107.         Write-Host "Connecting to Exchange Online Protection and Security (aka Security and Compliance)" -backgroundcolor black -foregroundcolor green
  108.         Connect-ippssession
  109.     }
  110.  
  111.     if ($Skype) {
  112.         #Skype For Business Module
  113.         Import-Module SkypeOnlineConnector
  114.         Write-Host "Connecting to Skype for Business Online" -backgroundcolor black -foregroundcolor green
  115.         $sfboSession = New-CsOnlineSession -UserName $AcctName
  116.         Import-PSSession $sfboSession
  117.     }
  118.  
  119.     if ($Teams) {
  120.         #Microsoft Teams Module
  121.         Write-Host "Connecting to Microsoft Teams" -backgroundcolor black -foregroundcolor green
  122.         Connect-MicrosoftTeams
  123.        
  124.         $SkypeRequired = Read-Host "Did you import the additionaly required skype module? Yes or No"
  125.            
  126.         if ($SkypeRequired -eq 'No') {
  127.             #Skype For Business Module
  128.             Import-Module SkypeOnlineConnector
  129.             Write-Host "Connecting to Skype for Business Online" -backgroundcolor black -foregroundcolor green
  130.             $sfboSession = New-CsOnlineSession -UserName $AcctName
  131.             Import-PSSession $sfboSession
  132.            
  133.         }
  134.     }
  135.  
  136.     if ($Az) {
  137.         #Azure Az Module
  138.         Write-Host "Connecting to Azure Az Module" -backgroundcolor black -foregroundcolor green
  139.         Connect-AzAccount
  140.     }
  141.  
  142.     if ($All) {
  143.         #Sharepoint Online Module
  144.         Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
  145.         Write-Host "Connecting to SharePoint Online" -backgroundcolor black -foregroundcolor green
  146.         Connect-SPOService -Url https://$DomainHost-admin.sharepoint.com
  147.  
  148.         #Azure AD Module
  149.         Write-Host "Connecting to other Azure AD Services" -backgroundcolor black -foregroundcolor green
  150.         Connect-AzureAD
  151.  
  152.         #Exchange Online Module
  153.         Write-Host "Connecting to Exchange Online Services" -backgroundcolor black -foregroundcolor green
  154.         connect-exopssession
  155.  
  156.         #Security and Compliance Module
  157.         Write-Host "Connecting to Exchange Online Protection and Security (aka Security and Compliance)" -backgroundcolor black -foregroundcolor green
  158.         Connect-ippssession
  159.  
  160.         #Skype For Business Module
  161.         Import-Module SkypeOnlineConnector
  162.         Write-Host "Connecting to Skype for Business Online" -backgroundcolor black -foregroundcolor green
  163.         $sfboSession = New-CsOnlineSession -UserName $AcctName
  164.         Import-PSSession $sfboSession
  165.  
  166.         #Microsoft Teams Module
  167.         Write-Host "Connecting to Microsoft Teams" -backgroundcolor black -foregroundcolor green
  168.         Connect-MicrosoftTeams
  169.  
  170.         #Azure Az Module
  171.         Write-Host "Connecting to Azure Az Module" -backgroundcolor black -foregroundcolor green
  172.         Connect-AzAccount
  173.     }
  174.  
  175.     Write-Host "Going to import modules with verbose switch so all commands are available" -backgroundcolor black -foregroundcolor green
  176.     pause
  177.     get-module | import-module -verbose
  178.     Clear-Host
  179.     Get-Command | Out-GridView
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement