Solved

Exchange modules in Power Shell ISE

Posted on 2014-09-24
14
156 Views
Last Modified: 2015-02-04
Is there a way to load the exchange modules into Power Shell ISE so I can run Exchange 2010 commands from within Power shell for scripting and scheduling jobs through task manager?  The exchange 2010 Management tools are already installe don my scripting server.
0
Comment
Question by:georgedschneider
  • 6
  • 5
14 Comments
 
LVL 12

Accepted Solution

by:
Vaseem Mohammed earned 375 total points
ID: 40342488
Run this 1liner in ISE with administrator rights.
Add-pssnapin microsoft.exchange.management.powershell.e2010
0
 

Author Comment

by:georgedschneider
ID: 40342586
Silly me I thought I had run this but apparently not.  Is there any way to have this automatically so if I schedule a script to run through task scheduler it will?
0
 

Assisted Solution

by:Roberto Oviedo
Roberto Oviedo earned 125 total points
ID: 40342600
In each script you want to schedule I recommend adding these lines:

#Check if the tools are installed Exchange (Based on code by Martin Pugh, www.thesurlyadmin.com)
$ExchangeServer = 'RemoteServerNameFQDN'
If (Get-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -Registered -ErrorAction SilentlyContinue)
{   
    $Snapin = "Microsoft.Exchange.Management.PowerShell.E2010"
}
ElseIf (Get-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin -Registered -ErrorAction SilentlyContinue)
{   
    $Snapin = "Microsoft.Exchange.Management.PowerShell.Admin"
}
Else
{   
    Write-Verbose "Unable to locate Exchange tools on localhost, attempting to remote to Exchange Server 2010/2013..."
    Try {
        $RemoteCredential = $host.ui.PromptForCredential("Credentials Exchange Server", "Please enter your user name and password for Exchange Server.", "", "NetBiosUserName")
        $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$ExchangeServer/PowerShell/ -Authentication Kerberos -Credential $RemoteCredential -ErrorAction Stop
        Import-PSSession $Session -ErrorAction Stop 
    }
    Catch { 
        Write-Host "Unable to import Exchange tools from $ExchangeServer" -ForegroundColor Red
        Write-Host "Error:  $($Error[0])" -ForegroundColor Magenta
        Exit
    }
}

#Connect to Exchange Management Shell
If ($Snapin)
{   #We know it exists, but is it already loaded?
    If (-not (Get-PSSnapin $Snapin -ErrorAction SilentlyContinue))
    {   Try {
            Add-PSSnapin $Snapin -ErrorAction Stop
        }
        Catch {
            Write-Host "Unable to load $Snapin because $($Error[0])" -ForegroundColor Red
            Exit
        }
    }
}

Open in new window

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 12

Assisted Solution

by:Vaseem Mohammed
Vaseem Mohammed earned 375 total points
ID: 40342625
1st you need to create a profile to store scripts which must load by default.
Run
if (!(test-path $profile )) 
{new-item -type file -path $profile -force}

Open in new window

This will create a profile, you can check by entering $profile which gives you the location of profile.ps1
To edit use
PSEdit $Profile

Open in new window

This will open the Microsoft.PowershellISE_profile.ps1
Put
Add-PSSnapin Microsoft.Exchange.Management.Powershell.E2010

Open in new window

and save the file.
When you launch ISE the Snap-In will be loaded upon startup.
0
 

Author Comment

by:georgedschneider
ID: 40342818
Is this for any user or just the currently logged on user?
0
 
LVL 12

Expert Comment

by:Vaseem Mohammed
ID: 40342853
For currently logged on user
0
 
LVL 12

Expert Comment

by:Vaseem Mohammed
ID: 40342855
0
 

Author Comment

by:georgedschneider
ID: 40345791
Is this what would be needed in order for me to create scripts to run against exchange and schedule them on my scripting machine?
0
 
LVL 12

Assisted Solution

by:Vaseem Mohammed
Vaseem Mohammed earned 375 total points
ID: 40347007
If you are scheduling / distributing scripts then better option is to use If-Else to check and load snapin.
$2010snapin = Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue
if($2010snapin)
{
    Write-Host "Snap-In already loaded"
    
}
else
{
    Write-Host "Not Present"
    Write-Host "Adding Exchange 2010 Snap-In"
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
}

Open in new window

0
 

Author Comment

by:georgedschneider
ID: 40361287
So basically all i need to do on my scripting machine that has Power shell, Exchange tools include this as part of the exchange scripts that I intend to run as a scheduled task.
0
 
LVL 12

Expert Comment

by:Vaseem Mohammed
ID: 40367677
Exchange tools will make the snap-in available on machine, If you open "Exchange Management Shell" the Snap-in will be loaded automatically, whereas if you open "Windows Powershell" the Snap-in will not be loaded in the session and hence you need to run the above mentioned code, so that when the script runs very 1st thing it does is to check the availability of Snap-in otherwise the script will fail.
0
 

Author Comment

by:georgedschneider
ID: 40395728
What is the difference between the various Powershell ISE profile types.  What are the hosts profile types used for?

Current user, PowerShell ISE
All users, PowerShell ISE
Current user, All hosts
All users, All hosts
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
Read this checklist to learn more about the 15 things you should never include in an email signature.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question