Quantcast
Viewing all articles
Browse latest Browse all 21975

add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin

I have a script (below) that was designed to be used by people who do not have access to Exchange. The idea is to check if ActiveSync is enabled for the user, it gives the ability to enable or disable ActiveSync, look for connected devices and remove any stale partnerships.

It works great, in ISE, but run it in Powershell and it says:

"add-pssnapin : The Windows PowerShell snap-in Microsoft.Exchange.Management.PowerShell.Admin' is not installed on this computer."

This is obviously not true as it loads the snap-in and runs the script fine in ISE (both 32 and 64 bit).

Can anyone tell me why it does not work in Powershell but does work in ISE? Every time I've encountered issues like this before it has been the other way around, fails in ISE but works in Powershell.

I am running Windows 8.1, Powershell 4. The domain is Windows server 2008 R2, Exchange is 2007 SP3.

Code:

add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
load-module activedirectory
$prompt = @"

************************************************************************************************************************
**                                      Please select from the options below                                          **
**                                                                                                                    **
**                                      s = Search ActiveSync Status                                                  **
**                                      e = Enable ActiveSync for User                                                **
**                                      d = Disable ActiveSync for User                                               **
**                                      c = Search For Device Connections                                             **
**                                      r = Remove Device Connection                                                  **
**                                      x = exit                                                                      **
**                                                                                                                    **
************************************************************************************************************************


"@
Clear-host
Do{
	$originalcolor = $host.UI.RawUI.ForegroundColor
	$host.UI.RawUI.ForegroundColor = "Yellow"
	$choice = Read-Host -Prompt $prompt
	$host.UI.RawUI.ForegroundColor = "Yellow"
	Switch($choice){
        s {$user = Read-Host 'Enter the email address to search for (email.address@bellevue.edu)' ; Get-CASMailbox $user | Select-Object ActiveSyncEnabled}
        c {$user = Read-Host 'Enter the mailbox to search for (Firstname.Lastname)' ; Get-ActiveSyncDeviceStatistics -Mailbox $user | 
    ft DeviceType, DeviceUserAgent, LastSuccessSync}
        r {$user = Read-Host 'Enter the email address (email.address@bellevue.edu) you wish to remove inactive (no sync in last 7 days) partnership(s) from' ; Get-ActiveSyncDeviceStatistics -Mailbox $user | Where-Object {$_.LastSuccessSync -le (Get-Date).AddDays("-7")} | Remove-ActiveSyncDevice -confirm:$false}
        e {$user = Read-Host 'Enter the email address to enable ActiveSync for (email.address@bellevue.edu)' ; get-mailbox $user | set-Casmailbox -ActiveSyncEnabled:$true}
        d {$user = Read-Host 'Enter the email address to disable ActiveSync for (email.address@bellevue.edu)' ; get-mailbox "$user" | set-Casmailbox -ActiveSyncEnabled:$false}
        x {break}

		default {write-host "Invalid selection, please try again." -ForegroundColor Red}
	}
}Until($choice -eq "x")


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>