Last active
September 11, 2017 16:50
-
-
Save miracles1315/c8491475ce16200b15a1347bd4bb76e1 to your computer and use it in GitHub Desktop.
The function creates a remote PowerShell session to the Office 365 "Skype For Business Online" service.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Connect-O365SkypeForBusinessOnline | |
{ | |
<# | |
.SYNOPSIS | |
The function creates a remote PowerShell session to the Office 365 'Skype For Business Online' service. | |
.DESCRIPTION | |
The function creates a remote PowerShell session to the Office 365 'Skype For Business Online' service. Valid Office 365 credentials must be supplied. The function has an alias of Connect-O365SFBO. | |
.PARAMETER Credential | |
Valid Office 365 credentials. | |
.EXAMPLE | |
PS C:\>$Credential = Get-Credential | |
PS C:\>Connect-O365SkypeForBusinessOnline -Credential $Credential | |
OR | |
PS C:\>$Credential = Get-Credential | |
PS C:\>Connect-O365SFBO -Credential $Credential | |
.EXAMPLE | |
PS C:\>Connect-O365SkypeForBusinessOnline -Credential [email protected] | |
OR | |
PS C:\>Connect-O365SFBO -Credential [email protected] | |
In the above examples, the user will be prompted for credentials, with [email protected] shown in the 'User name' field. A valid password will need to be supplied. | |
.EXAMPLE | |
PS C:\>Connect-O365SkypeForBusinessOnline | |
OR | |
PS C:\>Connect-O365SFBO | |
In the above examples, the user will be prompted for credentials. Valid Office 365 credentials will need to be supplied. | |
.INPUTS | |
Valid Office 365 credentials. | |
.OUTPUTS | |
The exported commands from the 'Skype For Business Online' service (Ex: Get-CsOnlineUser). | |
.NOTES | |
Last Updated: 9/11/17 | |
.LINK | |
New-CsOnlineSession | |
https://technet.microsoft.com/library/dn362831.aspx | |
https://technet.microsoft.com/library/dn362817.aspx | |
https://www.microsoft.com/en-us/download/details.aspx?id=39366 | |
#> | |
[CmdletBinding()] | |
Param | |
( | |
[PSCredential] $Credential = $Null | |
) | |
[String] $ModuleName = 'SkypeOnlineConnector' | |
[String] $ServiceName = 'Skype For Business' | |
[String] $FunctionName = 'Connect-O365SkypeForBusinessOnline' | |
[String] $ModuleDownloadURL = 'https://www.microsoft.com/en-us/download/details.aspx?id=39366' | |
Try | |
{ | |
Write-Verbose "Importing the $ModuleName module." | |
Import-Module $ModuleName -ErrorAction Stop | |
[Boolean] $ModuleImported = $True | |
} #End 'Try' block | |
Catch | |
{ | |
[Boolean] $ModuleImported = $False | |
Write-Warning "Unable to create a remote session to the Office 365 `'$ServiceName`' service because the `'$ModuleName`' module failed to successfully import (See the error, below, for details on the import failure.). Make sure the latest version of the module is installed (Last Known Download URL: $ModuleDownloadURL). If it is, try closing and relaunching Windows PowerShell/PowerShell ISE, and then running the $FunctionName function again.`n" | |
throw | |
} #End 'Catch' block | |
If($ModuleImported) | |
{ | |
If(!$Credential) | |
{ | |
Try | |
{ | |
Write-Verbose "Prompting user for Office 365 credentials." | |
$Credential = Get-Credential -ErrorAction Stop | |
} #End 'Try' block | |
Catch | |
{ | |
Write-Warning "User cancelled the request for credentials. Exiting the $FunctionName function." | |
} #End Catch block | |
} #End 'If' block | |
If($Credential) | |
{ | |
Try | |
{ | |
$Session = New-CsOnlineSession -Credential $Credential -ErrorAction Stop | |
$Global:SFBOxportedCommands = Import-PSSession $Session -ErrorAction Stop | |
Return $SFBOExportedCommands | |
} #End 'Try' block | |
Catch | |
{ | |
Write-Warning "Unable to create a remote session to the Office 365 `'$ServiceName`' service. See the error, below, for details on the failure.`n" | |
throw | |
} #End 'Catch' block | |
} #End 'If' block | |
} #End 'If' block | |
} #End 'Connect-O365SkypeForBusinessOnline' function | |
$FunctionAliasExists = Get-Alias -Name Connect-O365SFBO -ErrorAction SilentlyContinue | |
If(!$FunctionAliasExists) | |
{ | |
New-Alias -Name Connect-O365SFBO -Value Connect-O365SkypeForBusinessOnline | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment