Ben Hart
asked on
Powershell Script help request
I have the following script:
I'd like to change the ending to a get-pssession and if nothing is returned display that there are no sessions that exist. Like a confirmation that the session was closed successfully.
#Disabling all ExchangeOnline Services to a specific mailbox
#Aug 2015, Ben Hart @ Unified Brands
Import-Module MSOnline
# Imports the O365 Commandlets
$CloudCredential=Get-Credential -Credential "user@domain.com"
# Saves your User name and password
$CloudSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $CloudCredential -Authentication Basic -AllowRedirection -WarningAction SilentlyContinue
Import-PSSession $CloudSession -Prefix 365
# Sets the O365 Commands to start with 365
Connect-MsolService -Credential $CloudCredential
# Connects to O365 services
$user = read-host "Enter users email address to disable"
Set-365CasMailbox $user -PopEnabled $False
Set-365CasMailbox $user -ImapEnabled $False
Set-365CasMailbox $user -MapiEnabled $False
Set-365CasMailbox $user -OwaEnabled $False
Set-365CasMailbox $user -ActiveSyncEnabled $False
remove-pssession $CloudSession
I'd like to change the ending to a get-pssession and if nothing is returned display that there are no sessions that exist. Like a confirmation that the session was closed successfully.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can put anything you want inside the scriptblock portion (between the curly brackets) of the If statement.
ASKER
Awesome.. and so easy. Thanks!
Essentially, the existing "no sessions" is a Write-Output command.
ASKER