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

asked on

Powershell Script help request

Kinda like my last post:

#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 "bhart@unifiedbrands.net"
# 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

if ( !(Get-PSSession) ){"no sessions"
 write-host "Remote PSSession terminated"}

Open in new window



I'd like to return a 'write-host' if the email address entered is not found and allow the user to input another.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany 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

thanks qelmo!

Ill be back in the office in a couple days so I cant test it until then.
To have some feedback, you can remove the -ea silentlyContinue. Everything else needs some effort to get it right and nice.
works like a champ.  Thanks Q!