dmxop
 New Member Posts:9

 |
| 19 Jan 2010 01:45 PM |
|
Hello,
Please could someone help me. We would like to disable ActiveSync on all mailboxes except for users which are members of a security group "ActiveSync Allowed". I have had some success by scheduling powershell script to run on a daily basis to disable activesync for any users which may have been added/enabled during the previous day. I have managed to get this working by scheduleding the following:
Get-User -ResultSize Unlimited | Where {($_.WhenCreated -gt (get-date).adddays(-1))} | Set-CASMailbox –ActiveSyncEnabled $false
However I would like this to exclude a number of users. These users are a member of a security group "ActiveSync Allowed" Is it possible to somehow get all users in the Exchange 2007 environment but exclude members of this group from the above powershell? Or any alternative methods would be welcome (preferably not using the Quest QAD command - we dont have this in our environment).
Many Thanks Mark |
|
|
|
|
Karl Mitschke
 Basic Member Posts:457

 |
| 19 Jan 2010 02:35 PM |
|
Mark; Try this:
$groupidentity = $(Get-Group "ActiveSync Allowed").Identity.DistinguishedName
$date = (Get-Date).AddDays(-1).ToShortDateString()
Get-Mailbox -Filter{(memberofgroup -ne $groupidentity) -and (whencreated -gt $date)} -ResultSize unlimited |Set-CASMailbox -ActiveSyncEnabled $false
Karl |
|
http://unlockpowershell.wordpress.com
Co-Author, Windows PowerShell 2.0 Bible
-join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"}) |
|
|
dmxop
 New Member Posts:9

 |
| 20 Jan 2010 02:14 AM |
|
Thanks for your help. Howerver, I tried it but get the following error:
Get-Mailbox : Cannot bind parameter 'Filter' to the target. Exception setting "Filter": "Cannot convert value "19/01/2010" to type "System.DateTime". Error: "String was not recognised as a valid DateTime."" At line:1 char:20
Kind Regards Mark |
|
|
|
|
halr9000 PowerShell MVP, Site Admin
 Advanced Member Posts:565

 |
| 20 Jan 2010 05:17 AM |
|
Yeah, when I saw Karl's message I was worried this might happen. I see no reason for the ".ToShortDateString()" bit, try removing that and see if that does the trick. Converting a datetime object to a string is asking for trouble (in a localized world) and complicating things besides. |
|
Community Director, PowerShellCommunity.org Co-host, PowerScripting Podcast Author, TechProsaic |
|
|
dmxop
 New Member Posts:9

 |
| 20 Jan 2010 06:51 AM |
|
Many thanks that has worked a treat!
Thanks Mark |
|
|
|
|
Karl Mitschke
 Basic Member Posts:457

 |
|
AaronJAnderson
 New Member Posts:42

 |
| 26 Mar 2010 06:51 AM |
|
This is how I do it. |
eas.ps1
|
|
|
|
AaronJAnderson
 New Member Posts:42

 |
| 26 Mar 2010 07:21 AM |
|
#Adding Exchange Snap In to execute Exchange CmdLets in this script Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin # Disable ActiveSync for ALL accounts because Microsoft hates you get-Mailbox -ResultSize:unlimited | set-CASMailbox -ActiveSyncEnabled:$False -ErrorAction SilentlyContinue -WarningAction SilentlyContinue # Assign all members of the group to a dynamic array $allUsers = Get-DistributionGroupMember -Identity 'ActiveSync Users' # Loop through the array foreach ($member in $allUsers) { # Set ActiveSync for each member of the array $member | Set-CASMailbox –ActiveSyncEnabled $true } |
|
|
|
|
NetoworkITGuy
 New Member Posts:1

 |
| 17 Apr 2010 07:50 AM |
|
Thanks Aaron, your post inspired me to write my first PowerShell Script. Basically I just turned the main part into a function so I could implement it a little easier into my environment. I'm a VBS person but functions seem to work fine. They are entirely based off the scripts in this post. Hope this helps someone else.
#Adding Exchange Snap In to execute Exchange CmdLets in this script Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
# Disable ActiveSync and OWA for all Accounts get-Mailbox -ResultSize:unlimited | set-CASMailbox -OWAEnabled $False -ErrorAction SilentlyContinue -WarningAction SilentlyContinue get-Mailbox -ResultSize:unlimited | set-CASMailbox -ActiveSyncEnabled $False -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
#Function that enables OWA for members of each group function EnableOWA { param($enableGroup)
# Assign all members of the group to a dynamic array $allUsers = Get-DistributionGroupMember -Identity $enableGroup # Loop through the array foreach ($member in $allUsers) {
# Set OWA for each member of the array $member | Set-CASMailbox –OWAEnabled $true } }
#Function that enables ActiveSynce for members of each group function EnableActiveSync { param($enableGroup)
# Assign all members of the group to a dynamic array $allUsers = Get-DistributionGroupMember -Identity $enableGroup # Loop through the array foreach ($member in $allUsers) {
# Set ActiveSync for each member of the array $member | Set-CASMailbox –ActiveSyncEnabled $true } }
#DistrobutionGroups that allow webmail EnableOWA 'Allowed Webmail' EnableOWA 'IT Department'
#DistrobutionGroups that allow ActiveSync EnableActiveSync 'Allowed PhoneMail' EnableActiveSync 'IT Department' |
|
|
|
|
AaronJAnderson
 New Member Posts:42

 |
| 18 Apr 2010 07:54 AM |
|
novasamurai, I think you made it more complicated than it needs to be, that's part of the beauty of powershell, you need far less lines of code to do the same things. |
|
|
|
|
tippet5x
 New Member Posts:2

 |
| 14 Jul 2010 12:15 PM |
|
this would be great.Getting an Error [PS]$groupidentity = $(Get-Group"ActiveSync Allowed").Identity.DistinguishedName Get-Mailbox -Filter{(memberofgr oup -ne $groupidentity)} -ResultSize unlimited |Set-CASMailbox -ActiveSyncEnabled $false Unexpected token 'Get-Mailbox' in expression or statement. At line:1 char:90 + $groupidentity = $(Get-Group "ActiveSync Allowed").Identity.DistinguishedName Get-Mailbox <<<< -Filter{(memberofgroup -ne $groupidentity)} -ResultSize unlimited |Set-CASMailbox -ActiveSyncEnabled $false |
|
|
|
|
Paul Carroll
 New Member Posts:1

 |
| 12 Aug 2011 01:46 AM |
|
Two questions and an error I am seeing,
1. Does this text get entered as one command on one line? 2. When I put it into powershellise.exe and try to run it, it fails, I removed the "ToShortDateString()" bit too but it still fails
The error is PS D:\Users\pcarroll\Documents> $groupidentity = $(Get-Group "GBS ActiveSync Approved").Identity.DistinguishedName The term 'Get-Group' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, veri fy that the path is correct and try again. At line:1 char:29
when I run that section in a powershell command window, it works.
What am I doing wrong?
Regards,
Paul.
Scratch this post, figured it out as I wasn't at the correct path in Powershell to run the PS1 file |
|
|
|
|
chatou7
 New Member Posts:1

 |
| 02 Sep 2011 09:17 AM |
|
Hello All !
What about Exchange 2003 users ??? Does anyone know of a PowerShell script to disable Exchange 2003 users ?
Thanks Chantal |
|
| Chantal |
|
|
Kristy
 New Member Posts:1

 |
| 05 Oct 2011 06:59 AM |
|
I am new to the community. Would Karl's suggestion also work for members of a DL? I had some VB classes in school, but it has been a while.
|
|
|
|
|