Link to home
Start Free TrialLog in
Avatar of Ben Hart
Ben HartFlag for United States of America

asked on

Powershell Script help request

I have the following script:

#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

Open in new window


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
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ben Hart

ASKER

Possibly. How would I combine that with a write-host?
You can put anything you want inside the scriptblock portion (between the curly brackets) of the If statement.
Awesome.. and so easy.  Thanks!
Essentially, the existing "no sessions" is a Write-Output command.