![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | sourcing a file in a script I'll probably kick myself after reading the answer, but for the life of me I can't figure out how to source a file in PowerShell. Specifically, I've got some files containing some variables common to some scripts I'll be running. (file paths for example) Rather than inserting them into each script and then having to do a large-scale hunt if/when they change, I'd like to just have a one-liner to include their content. Plus some of them will be maintained by somebody else so I would rather they not have to edit the scripts. Basically, what is PS's version of the Linix file sourcing or PHP's include()? Thanks, Jason |
My System Specs![]() |
| | #2 (permalink) |
| | Re: sourcing a file in a script Dot-source the script: .. <script> # the space is optional -- Kiron |
My System Specs![]() |
| | #3 (permalink) |
| | Re: sourcing a file in a script You need to "Dot source" the file. Basically, its ". <filename>". Check "Get-ScriptDirectory to the Rescue" by Jeffrey Snover http://blogs.msdn.com/powershell/arc...directory.aspx Shay http://scriptolog.blogspot.com Quote: > I'll probably kick myself after reading the answer, but for the life > of me I can't figure out how to source a file in PowerShell. > > Specifically, I've got some files containing some variables common to > some scripts I'll be running. (file paths for example) Rather than > inserting them into each script and then having to do a large-scale > hunt if/when they change, I'd like to just have a one-liner to include > their content. Plus some of them will be maintained by somebody else > so I would rather they not have to edit the scripts. > > Basically, what is PS's version of the Linix file sourcing or PHP's > include()? > > Thanks, > Jason |
My System Specs![]() |
| | #4 (permalink) |
| | Re: sourcing a file in a script The space is optional when dot-sourcing from a variable: $scripts= 'c:\dir1\script' ..$script And it's required when dot-sourcing from a literal string .. c:\dir1\script Sorry for the misdirection ![]() -- Kiron |
My System Specs![]() |
| | #5 (permalink) |
| | Re: sourcing a file in a script Expanding on Kiron's great samples: param([string]$scriptToSource) ..$scriptToSource Shay http://scriptolog.blogspot.com Quote: > The space is optional when dot-sourcing from a variable: > > $scripts= 'c:\dir1\script' > > .$script > > And it's required when dot-sourcing from a literal string > > . c:\dir1\script > > Sorry for the misdirection ![]() > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: sourcing a file in a script Yeah, commence kicking. I got off on a wild mental tanget and could not pull myself back. Thanks. Jason |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Dot-sourcing and scope | PowerShell | |||
| problem passing args to script 'There is no script engine for file extenstion' | VB Script | |||
| Dot sourcing multiple code files | PowerShell | |||
| Script file has 'OS Handle' error when run from script | PowerShell | |||
| Can you drag-n-drop a file on top of a PS script to run the script? | PowerShell | |||