Back to script samples page
Managing a PowerShell session

In PowerShell, a session is the equivalent to having a console open on a remote server. For Office 365, these sessions enable you to administer your online services.

Each Office 365 service has a different way to create a session. In this script we have used Exchange Online as an example.

Importing a PowerShell session makes the commands in the remote session available for use within your active PowerShell window.

#Managing a PowerShell session

#Capture administrative credential for future connections.
$credential = get-credential

#Creates an Exchange Online session.
$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $credential -Authentication Basic -AllowRedirection

#Import session commands.
Import-PSSession $ExchangeSession 

#The commands in this session are now available for you to use as required.
#In this example, we will simply use a command that retrieves information.

#Once finished, it is important to close your session.
Disconnect-PSSession $session

#And finally, remove your session.
Remove-PSSession $session

#Additional session management for PowerShell details.

#Ending a session for Skype for Business is identical to the process used in this script. 
#However, for a SharePoint online session, we simply replace the Disconnect-PSSession and Remove-PSSession commands with ‘Disconnect-SPOService’. 
#No additional arguments are needed to perform this command.
Downloaded 0 times
- - - - - (0)

No Comments