I have a runbook designed for doing some tasks in specific AD accounts. Of many tasks , I am facing problem in three specific powershell scripts which are failing. The three scripts do the following tasks respectively:-
- Disable ActiveSync
- Check for out of office Status
- Remove all rules and alerts
The records are fetched from the database all at once , and all the subsequent tasks/ nodes are executed for all the records parallely and not by fetching records one by one and processing each record individually. I think the RAM consumption is getting very high whenever the number of records for processing is high.
I am attaching the snapshots of the three scripts for your reference :-
The snapshots attached below are of the Scripts being used , where I am facing the issue.
Any suggestion / observation would be of great help. Thank You!
(Disable Active Sync Powershell Script)
$Username = “XXXXXXXXXXX”
$Password = “XXXXX”
$ServerName = “Prodserver1”
$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $Username,$securePassword
$PSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://Prodserver1/PowerShell -Authentication Kerberos -Credential $credential
Import-PSSession $PSSession
$Script={
Set-CASMailbox -Identity EmpID -ActiveSyncEnabled $false
}
Invoke-Command -Session $PSSession -ScriptBlock $Script
Remove-PSSession $PSSession
#——————————————————————————————————————————–
#(Remove all rules and alerts Powershell Script)
$Username = “XXXXXXXXXX”
$Password = “XXXXX”
$ServerName = “Prodserver1”
$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $Username,$securePassword
$PSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://Prodserver1/PowerShell -Authentication Kerberos -Credential $credential
Import-PSSession $PSSession -DisableNameChecking
$Script={
Get-InboxRule -Mailbox EmpID | Remove-InboxRule -Confirm:$False -Force
}
Invoke-Command -Session $PSSession -ScriptBlock $Script
Remove-PSSession $PSSession
#————————————————————————————————————————————–
#(Check Out Of Office status)
$Username = “XXXXXXXXXX”
$Password = “XXXXX”
$ServerName = “Prodserver1”
$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $Username,$securePassword
$PSSession2 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://Prodserver1/PowerShell -Authentication Kerberos -Credential $credential
Import-PSSession $PSSession2
$Script={
$OOO = Get-MailboxAutoReplyConfiguration -identity “Distinguished Name” | select AutoReplyState
$OutOfOffice = $OOO.AutoReplyState
}
Invoke-Command -Session $PSSession2 -ScriptBlock $Script
Remove-PSSession $PSSession2