Good day all. I would like to log onto exchange online, run two scripts I have already created then close the session to exchange online. One of these scripts give data output and the other doesn't show data as often. This is what I created
but I am not sure its working as planned. I am thinking I need to put in a WAIT, DELAY, TIMEOUT or some other pause some how. Tips appreciated.
Email-Compliance.ps1
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Write-Output "Enabling audit tracking on all accounts"
. \\s.com\NETLOGON\scripts\email-SET-audit-enabled_v1.0.ps1
Write-Output "Setting calendars default to Limited Details"
. \\s.com\NETLOGON\scripts\email-SET-calendar-permissions_v1.0.ps1
Write-Output "Closing Exchange Online connection"
Remove-PSSession $Session
Below is each one of the nested PS1 scripts;
email-SET-audit-enabled_v1.0.ps1
Get-Mailbox | where-object {$_.AuditEnabled -eq $False } | set-mailbox -AuditEnabled $true |ft -a
email-SET-calendar-permissions_v1.0.ps1
foreach($user in Get-Mailbox -RecipientTypeDetails usermailbox) {
$calendar = $user.alias+":\calendar"
Set-MailboxFolderPermission -Identity $calendar -user default -AccessRights LimitedDetails|
Where-Object {
$_.accessrights -NE "LimitedDetails" -and
$_.identity -NE "CEO:\calendar" -and
$_.identity -NE "HR:\calendar" }}