tags:

views:

37

answers:

2

can I load a ps1 file from within a ps1 file.

The end goal is to make a ps1 file that I put in my profile on all my computers and have a floating profile that I can put paths to pocket utilities in. I'll probably put this in a code repo, or some outside sharing mechanism.

+4  A: 

This is most definitely supported in powershell and I have this exact same setup on my machine

Normal Profile.ps1 Contents

. ~\winconfig\PowerShell\Profile.ps1

The Profile.ps1 in WinConfig\PowerShell is my version controlled profile which has all of my custom fun inside of it. I have a script which simply generates the standard Profile.ps1 in the normal powershell directory whenever I get a new machine.

JaredPar
A: 

I have all my scripts primarily on a flash drive (and some backups on computers at home/work). At the flash drive I have my profile script that creates all my custom conversion functions, drives etc.

What I want is to load the profile script from flash disk every time I run PowerShell.
So, the code in my $profile at all the computers I work with looks like this:

#drive name of my flash; obviously different on each computer
$global:psflash = "g:\"

# if my flash disk is available, load my profile script from the flash disk
if (test-path $psflash) {
  . (join-path $psflash 'dev\powershell\PsProfile.ps1')
}

The good side effect is that all my scripts can use the global variable $psflash to import other scripts they depend on or other modules in the same way as done in my profile (using join-path) any time later.

stej