Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Start Up Paths in Windows Powershell

$
0
0

Hello,

I have a novice question. I have three environments(dev,qa,prod) and would like to manage paths so that hard-coding is minimal. The directory structure for the three environments is identical. I have paths to manage like:

\\domain\somecompany\PRD\XXX

\\domain\somecompany\QA\XXX

\\domain\somecompany\DEV\XXX

I thought I might put the environment path in one file globals.ps1 that was dot sourced from the current directory. Thus this file might for DEV set a variable holding the path 

\\Domain\somecompany\DEV

Then I thought I could control the current directory by putting an entry in the profile for the user. In all subsequent scripts I would only need to dot source 

As a first test on my local machine I tried something like this:

1. Set the Powershell startup directory to a starting script directory by adding the following to $profile. 

Set-Location "C:\my script directory"

2. In "c:\my script directory" I have a script Globals.ps1 that (in theory would hold all the other paths but at present) sets one variable holding a path

$RootPath = "C:\some\other\path"

3. Also in "c:\my script directory" I have a script called GlobalsTest.ps1 that contains:

.\Globals.ps1 
Write-Host $MyPath\test.txt

Instead of getting  the output "c:\some\other\path\test.txt" I get "\test.txt". If I take the quotes off in the defintion of $MyPath I get an error. What am I missing?

Thanks in advance



Viewing all articles
Browse latest Browse all 21975

Trending Articles