Solved

Exchange modules in Power Shell ISE

Posted on 2014-09-24
14
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

623 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