ahmshaik
asked on
Customising Exchange Activesync Powershell script
Hi All,
We are seeing couple of activesync mailboxes getting disabled/enabled offen. This is because of users having admin access are changing adhocly.
Planning to have a script in place to enable/disable activesync and maintain a log to track of all changes with date and time.
Below is the script to enable/disable Activesync
But my requirement is
1. read a user to enable or disable activesync
2. Do u want to enable or disable active sync
3. If user wants to enable AS
Then below conditions
if AS is not enabled and if CA#1 is empty
Enable ActiveSync and update CA#1 as Enable
Else IF AS is enabled & CA#1 is empty/disable
Inform like AS is already enabled for the user, but CA#1 is not updated/disable
Do u want to update CA#1 -> If yes -> Update CA#1
Else if AS is not enable & if CA#1 is updated as enable
Inform like AS is not enabled for the user, but CA#1 is updated
Do u want to enable Active sync
Else
inform both AS is enabled and CA#1 is updated.
4. If user wants to disable
then the same logic but have to disable...
Please let me know the conditons to be added in the script and let me know if we can have some good output with
1. Admin info - who has updated the AS & CA
2. Date and time
3. User info - whose details got updated.
This will allow me to track admins who are enabling/disabling the requests and also will be very easy to manage AS.
We are seeing couple of activesync mailboxes getting disabled/enabled offen. This is because of users having admin access are changing adhocly.
Planning to have a script in place to enable/disable activesync and maintain a log to track of all changes with date and time.
Below is the script to enable/disable Activesync
$name=Read-Host Enter the SMTP address of the account to be ActiveSync ENABLED
$a = get-date
set-mailbox -id $name -CustomAttribute1 'Enable'
set-casmailbox -id $name -ActiveSyncEnabled $true -ActiveSyncMailboxPolicy 'Default - Default Policy + Encryption'
echo $a >> c:\temp\scripts\EAS\log.txt
get-casmailbox -id $name | ft -autosize PrimarySMTPAddress,ServerName,ActiveSyncMailboxPolicy,ActiveSyncEnabled | out-file -append c:\temp\scripts\EAS\log.txt
get-casmailbox -id $name | ft -autosize PrimarySMTPAddress,ServerName,ActiveSyncMailboxPolicy,ActiveSyncEnabled
But my requirement is
1. read a user to enable or disable activesync
2. Do u want to enable or disable active sync
3. If user wants to enable AS
Then below conditions
if AS is not enabled and if CA#1 is empty
Enable ActiveSync and update CA#1 as Enable
Else IF AS is enabled & CA#1 is empty/disable
Inform like AS is already enabled for the user, but CA#1 is not updated/disable
Do u want to update CA#1 -> If yes -> Update CA#1
Else if AS is not enable & if CA#1 is updated as enable
Inform like AS is not enabled for the user, but CA#1 is updated
Do u want to enable Active sync
Else
inform both AS is enabled and CA#1 is updated.
4. If user wants to disable
then the same logic but have to disable...
Please let me know the conditons to be added in the script and let me know if we can have some good output with
1. Admin info - who has updated the AS & CA
2. Date and time
3. User info - whose details got updated.
This will allow me to track admins who are enabling/disabling the requests and also will be very easy to manage AS.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Hi Rajitha,
I am getting the below error while executing the script.
I am getting the below error while executing the script.
Enter the SMTP address of the account to manage Active Sync: ahmed@test.com
Get-Date : Cannot bind parameter 'Date'. Cannot convert value "log.txt" to type "System.DateTime". Error: "The string was not recognized as a valid D
ateTime. There is a unknown word starting at index 0."
At C:\\Ahmed\Activesync.ps1:2 char:9
+ get-date <<<< >> add-content log.txt
+ CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand
change this line "get-date >> add-content log.txt" to "get-date | add-content log.txt"
ASKER
Thanks for your quick response.
I am not getting any errors now. But when i enter emailaddress its accepting and script execution is completed. I believe it is not entering in any condition.
I even tried to give alias name,logon name as input but no Luck.
I am not getting any errors now. But when i enter emailaddress its accepting and script execution is completed. I believe it is not entering in any condition.
I even tried to give alias name,logon name as input but no Luck.
Try to print $Status and $CAValue within the script so that we can check if the commands work.
ASKER
I got the below result.
$status = test.com/Users/ahmshaik
$cavalue = Shaik,AhmedAli (User)
$status = test.com/Users/ahmshaik
$cavalue = Shaik,AhmedAli (User)
what is this test.com/Users/ahmshaik? I thought you were giving email address. Try the below command individually
$Status = Get-CASMailbox -Identity "emailaddress"
I presume something wrong with the input.
Those variables should not be single valued. you must get a set of values.
$Status = Get-CASMailbox -Identity "emailaddress"
I presume something wrong with the input.
Those variables should not be single valued. you must get a set of values.
ASKER
Hi Rajitha,
I am giving email address but still getting some error.
Enter the SMTP address of the account to manage Active Sync: ahmed@test.com
Get-CASMailbox : The operation could not be performed because object 'emailaddress' could not be found on domain controlle
.
At C:\Ahmed\Activesync.ps1:3 char:25
+ $Status = Get-CASmailbox <<<< -identity "emailaddress"
+ CategoryInfo : InvalidData: (:) [Get-CASMailbox], ManagementObjectNotFoundEx ception
+ FullyQualifiedErrorId : 6EB7296,Microsoft.Exchange .Managemen t.Recipien tTasks.Get CASMailbox
Shaik,AhmedAli (User)
Also just to confirm I tried running the below Cmlet and getting the below output.
I think we should get only email address here in the output.
[PS] C:\Ahmed>Get-CASMailbox -Identity ahmed@test.com
Name ActiveSyncEnabled OWAEnabled PopEnabled ImapEnabled
---- ----------------- ---------- ---------- -----------
ahmshaik True True True True
I am giving email address but still getting some error.
Enter the SMTP address of the account to manage Active Sync: ahmed@test.com
Get-CASMailbox : The operation could not be performed because object 'emailaddress' could not be found on domain controlle
.
At C:\Ahmed\Activesync.ps1:3 char:25
+ $Status = Get-CASmailbox <<<< -identity "emailaddress"
+ CategoryInfo : InvalidData: (:) [Get-CASMailbox], ManagementObjectNotFoundEx
+ FullyQualifiedErrorId : 6EB7296,Microsoft.Exchange
Shaik,AhmedAli (User)
Also just to confirm I tried running the below Cmlet and getting the below output.
I think we should get only email address here in the output.
[PS] C:\Ahmed>Get-CASMailbox -Identity ahmed@test.com
Name ActiveSyncEnabled OWAEnabled PopEnabled ImapEnabled
---- ----------------- ---------- ---------- -----------
ahmshaik True True True True
No... what you are getting is right. You should get the details of the CAS account.
In your first command..You must run it as below (i gave email address so that you can specify one)
$name=Read-Host "Enter the SMTP address of the account to manage Active Sync"
$Status = Get-CASmailbox -Identity $name
$Status
$CAValue = Get-Mailbox $Name
$CAValue
In your first command..You must run it as below (i gave email address so that you can specify one)
$name=Read-Host "Enter the SMTP address of the account to manage Active Sync"
$Status = Get-CASmailbox -Identity $name
$Status
$CAValue = Get-Mailbox $Name
$CAValue
ASKER
Hi Rajitha,
This Question is an escalated one as I have not got any response from any expert till certain time.
You have accepted my escalated query & given an awesome script for my custom requirment.
Thanks a lot.
I am feeling vey bad to give only 500 points.Wish to give u more and more points.
This Question is an escalated one as I have not got any response from any expert till certain time.
You have accepted my escalated query & given an awesome script for my custom requirment.
Thanks a lot.
I am feeling vey bad to give only 500 points.Wish to give u more and more points.
No problem AhmedAli and Thank You. As this was neglected question i get 200 more points..total 700 :)
ASKER
Thats really gr8.
I am very happy for that.
I am very happy for that.
ASKER
Many thanks for developing a script for me based on my requirement. I will try to run it and get back to you if I get any errors.