Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

ISE Relative paths

$
0
0

If I put a script and a text file in the same directory the following works:
MyPSScript.ps1:
Get-Content "Mytextfile.txt"
But if I run is in ISE (F5) I get an error :
 Cannot retrieve the dynamic parameters for the cmdlet. SQL Server PowerShell provider error: Path {..} does not exist. Please specify a valid path.
This is even though I have saved the .ps1 file in the same directory as the file I'm trying to read.
If I go to a PS prompt in the folder and run the saved script "MyPSScript.ps1", it works as expected.

I can cook the .ps1 file like this:
Get-Content "$(split-path $psISE.CurrentFile.FullPath)\Mytextfile.txt"
It now works in ISE but not normal powershell prompt.

I want to write a script that read/writes to files. I want to write it in ISE, test and then run from the prompt when I've ironed out the bugs. Is that so much to ask? I just want to use relative folder reference for the in/out files and just save them when the .ps1 file is. I don't want to enter fixed path names.

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles