Skip to content

Instantly share code, notes, and snippets.

@jacksoneyton
Created February 26, 2016 18:05
Show Gist options
  • Save jacksoneyton/9c88307d08787f77c6fe to your computer and use it in GitHub Desktop.
Save jacksoneyton/9c88307d08787f77c6fe to your computer and use it in GitHub Desktop.
ConnectTo-ExchangeShell
function ConnectTo-ExchangePS {
<#
.SYNOPSIS
Gathers information about exchange to automatically run the correct Exchange PS
.DESCRIPTION
Imports exchange modules and connects to the exchange server, this allows exchange PS scripts
to be run directly from a standard powershell window.
.NOTES
Version: 1.0
Author: Jackson Trevor Eyton
Creation Date: 11/15/13
.EXAMPLE
ConnectTo-ExchangePS
#>
#set base exchange install path
$2007installdir = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Exchange\Setup).Services
$2010installdir = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\ExchangeServer\v14\Setup).Services
$2013installdir = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup).Services
$ScriptCache = "C:\windows\ltsvc\packages\ADScripts\"
#set exchange ver. variables
$exch2013 = $2013installdir+="\Bin\RemoteExchange.PS1"
$exch2010 = $2010installdir+="\Bin\RemoteExchange.PS1"
$exch2007 = $2007installdir+="\Bin\Exchange.PS1"
# Test for Files
if(test-path $exch2010)
{
echo "installing ps for 2010"
. $exch2010
}
elseif(test-path $exch2013)
{
echo "installing ps for 2013"
. $exch2013
}
elseif(test-path $exch2007)
{
echo "installing ps for 2007"
. $exch2007
}
else
{
echo "error"
}
#Connect PS to exchange server and import AD modules
ConnectTo-ExchangePS -auto
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment