Add Exchange to PowerShell ISE

by ewkilian at 2013-01-30 02:23:50

Hello,
I’m French, my english is very Bad sorry.

To administre my Exchange with Powershell, I want add Exchange to Powershell ISE.
I try to add a subMenu to Powershell ISE as the site explains : http://eightwone.com/2012/10/25/adding-exchange-shell-items-to-powershell-ise/

I execute the script :

$psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add(
"Connexion vers Exchange", {
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
. $env:C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1
Connect-ExchangeServer –auto
},
"Control+Alt+1"
)


Result the error ( sorry french error ) :

Vous ne pouvez pas appeler de méthode sur une expression ayant la valeur Null.
Au niveau de C:\connecteur_Exchange_PS_ISE.ps1 : 1 Caractère : 52
+ $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add <<<< (
+ CategoryInfo : InvalidOperation: (Add:String) , RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull


I thinks that the problem become from the code :
. $env
freaky

I don’t know.
I thank you in advance for your help
EwKilian
by DonJ at 2013-02-01 14:28:53
I’m sorry, I don’t know enough French to understand what the error is telling you. It seems to say you’re passing a Null value to a method.

The ". $env" is "dot-sourcing" a script. That is, it is running a script without creating a scope around it. The script path follows - and I think that may be your problem. $env represents PowerShell’s environment variable drive, but you’re giving it a full path and filename. Have you tried just removing the $env?

In the post you reference, the authored used $env:ExchangeInstallPath\bin\RemoteExchange.ps1. That’s because he’s referring to the ExchangeInstallPath environment variable. You’re not referring to an environment variable, you’re giving it a complete path that starts with C:. So the $env seems superfluous.
by AsifSaif at 2013-02-10 10:53:44
As DonJ said, either change the path remove $env, or if its just loading exchange snapin, i have simplified it like this one liner,

$psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add("Connect to Exchange", {Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010}, "Control+Alt+E")

Regards,
Asif Saif