I can not remember from time to time how to start remote powershell towards different services. I just made a script to make things easier for myself. There is always room for improvement, to reuse credentials, but sometimes I need to use different accounts.
function Show-Menu
{
param (
[string]$Title = ‘Powershell Services’
)
cls
Write-Host “================ $Title ================”Write-Host “1: Press ‘1’ Azure Active Directory.” -ForegroundColor Green
Write-Host “2: Press ‘2’ Exchange Online.” -ForegroundColor Green
Write-Host “3: Press ‘3’ Skype for Business.” -ForegroundColor Green
Write-Host “4: Press ‘4’ SharePoint Online.” -ForegroundColor Green
Write-Host “5: Press ‘5’ Security and Compliance Center.” -ForegroundColor Green
Write-Host “Q: Press ‘Q’ to quit.” -ForegroundColor Green
}Show-Menu –Title ‘Powershell Services’
$selection = Read-Host “Please choose Service”
switch ($selection)
{
‘1’ {
‘You chose option #1 – AzureAD’
# Azure Active Directory
$Credential = Get-Credential
Connect-MsolService -Credential $Credential
} ‘2’ {
‘You chose option #2 – Exchange Online’
# Exchange Online
$credential = Get-Credential
$exosession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $credential -Authentication Basic –AllowRedirection
Import-PSSession $exosession
} ‘3’ {
‘You chose option #3 – Skype FB’
# Skype for Business
$credential = Get-Credential
$skypesession = New-CsOnlineSession -Credential $credential
Import-PSSession $skypesession
} ‘4’ {
‘You chose option #4 – SharePoint Online’
# SharePoint Online
$Credential = Get-Credential
Connect-SPOService -url https://<enter sitename here>-admin.sharepoint.com -Credential $credential
} ‘5’ {
‘You chose option #5 – Security and Compliance’
# Security and Compliance Center
$credential = Get-Credential
$ccsession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection
Import-PSSession $ccsession
} ‘q’ {
return
}
}