Exchange 2007, Powershell, Disable all Activesync Options except for users who are member of a Distribution group

by butsch 13. December 2012 21:48

 

Exchange 2007, Powershell, Disable all Activesync Options except for users who are member of a Distribution group

 

# Activesync Robot Script for Exchange 2007
# Exchange 2007 (2010 has) does not have the option to disable new added activesync partners automatic.
# -----------------------------------------------------------------------------------------------------
# M.Butsch
# 1) Disables all Activesync Options for ALL new User
# 2) Enables Activesync for all users who are member of the Distribution group "activesync"


#Prueft ob die Snap Ins schon geladen sind und skipt diese falls schon vorhanden (Änderung/Butsch/13.12.2012)

If (@(Get-PSSnapin -Registered | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 1) 
 {
     If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0)
  {
         Write-Host "Loading Exchange Snapin Please Wait...."
  Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
  }
        }

#Load Exchange PS Snapin
If (@(Get-PSSnapin -Registered | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.Admin"} ).count -eq 1)
 {
 If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.Admin"} ).count -eq 0)
  {
         Write-Host "Loading Exchange Snapin Please Wait...."
  Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
  }
        }

# Disable ActiveSync 
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'

# Loop through the array 
foreach ($member in $allUsers) {

# Set ActiveSync for each member of the array 
$member | Set-CASMailbox –ActiveSyncEnabled $true
}

   

How to make this work on a Exchange 2007 Server:

1) Copy the File to c:\batch\activesync.ps1

2) Create a LINK on the Desktop

TARGET: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -psconsolefile exshell.psc1 -noexit -command "& {c:\batch\activesync.ps1}"

RUNIN: "C:\Program Files\Microsoft\Exchange Server\Bin"

You also MAY have to edit the Powershell RUn POLICY > Please be carefull what you do. With this command you can run all PS1 scripts and also virus if you ever have.

Set-ExecutionPolicy Unrestricted

http://technet.microsoft.com/en-us/library/ee176961.aspx 

Changing the Windows PowerShell Script Execution Policy

The Set-ExecutionPolicy cmdlet enables you to determine which Windows PowerShell scripts (if any) will be allowed to run on your computer. Windows PowerShell has four different execution policies:

  • Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode.
  • AllSigned - Only scripts signed by a trusted publisher can be run.
  • RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.
  • Unrestricted - No restrictions; all Windows PowerShell scripts can be run.

   

Tags:

Comments are closed

Werbung von Drittfirmen (Nicht Butsch Informatik):

Werbung von Drittfirmen via Google Adsense: