InterOp: Using a .NET based component from a non .NET platform by creating Isolated Application
Skype Automation in Powershell : Don’t have to dial in conference codes anymore

Executing Powershell Scripts in the Same Execution Context

Recently I have been trying to do almost everything in Powershell. With the release of Powershell V2 RC and the awesome visual debugger that comes with Powershell called Powershell ISE, I have a Powershell window open at all times. I am getting my google calendar events form command line, doing recursive ftp uploads and download as well. Now I have started to even do outlook automation with PS.

The Problem

Any slightly efficient developer would write functions and reuse them later. So I tended to write functions add kept on adding them to my Powershell profile file. After a while that turned a little messy and hard to manage. So now I thought why don’t write different script files put my functions in there and use them when needed. So I created functions for Google Data API, Outlook functions. Now when I call them from the prompt, after execution of the script the functions are no longer there. It is because the scriptblock runs in a different execution context and after execution the context is removed. So the functions I have put the file no longer exist when I call them.

For example I have written a function in myfunc.ps1 to convert string into base64 string which looks like this

function tobase64 ( $asciistring )
  return [Convert]::ToBase64String([System.Text.Encoding]

Now after running the script .\myfunc.ps1 when I call the function, it no longer works.


After running around the internet for hours, looking for a solution to run scripts in the same executions context and trying out several different approaches, I was about to give up. Then I found the worlds easiest solution in Donn Felkers blog. All you need to do is to add a simple dot ( “.” ) at the start of the line to make it run the in the same context.

So if you were running the script like this,


You should run it like this

. .\myfunc.ps1 
. ‘c:\somefolder\myfunc.ps1’

See the added dot? That does the trick. I wish this was advertized more, then I wouldn’t have had to search for hours to find a solution.

kick it on


Ibrahim Abdul Rahim


Sorry it took so long to find the 'trick'. Its pretty well known for those who know it. Lame, I know.

What keywords did you search for? Its documented in
Get-Help about_scopes


Shafqat Ahmed

I searched with the web with my blog entry title, "Executing Powershell Scripts in the Same Execution Context". Since I could not get anything ... I wrote this down as a blog entry so that people like me who searches with the same keywords finds the answer.

yep ...pretty lame.

viagra online

(CLI) with the possibility of writing and combination of commands through scripts (scripts in English). It is much more rich and interactive than its predecessors, from DOS to Windows XP. The console interface is designed for use by systems administrators, in order to automate tasks or perform them more controlled.


Have they settled on Wes Johnson? Are they open to moving back in the lottery? The Nets need to turn this pick into some kind of valuable piece that can help attract a free agent. They already have center Brook Lopez and point guard Devin Harris; now add a starter (and they hope a potential star) with this pick to go with the max free agent they can bring in this summer. Altogether, this has the makings of an impressive starting lineup: Harris, shooting guard Courtney Lee, Johnson, power forward Carlos Boozer (a likely free-agent target next week) and Lopez.
Read more:

cialis  online

The fat or lard is the accumulation of fat found between the meat and leather pork and travels through the body of the animal. Stresses its characteristic odor Iberian pigs, depending on the area from which it was drawn are called: Bacon back or spine, or magroso belly bacon, etc.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment

Comments are moderated, and will not appear until the author has approved them.

Your Information

(Name and email address are required. Email address will not be displayed with the comment.)