Ben Hart
asked on
Powershell Script help request
Kinda like my last post:
I'd like to return a 'write-host' if the email address entered is not found and allow the user to input another.
#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"}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To have some feedback, you can remove the -ea silentlyContinue. Everything else needs some effort to get it right and nice.
ASKER
works like a champ. Thanks Q!
ASKER
Ill be back in the office in a couple days so I cant test it until then.