![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | How to use function in other scriptfiles? Hello is it possible to run a function or scriptblock in another scriptfile? for example i have a script "myfunctions.ps1" with some functions and scriptblocks which i often use. now i wish to run in another script a defined function in "myfunction.ps1". with best regards Jens |
| | #3 (permalink) |
| Guest | RE: How to use function in other scriptfiles? "Jens Schulze" wrote: > Hello > is it possible to run a function or scriptblock in another scriptfile? for > example i have a script "myfunctions.ps1" with some functions and > scriptblocks which i often use. now i wish to run in another script a > defined function in "myfunction.ps1". > > with best regards Jens > Put all script files that contain the functions you need at the beginning of your script and put a dot "." and a space infront of it. This is called "dot"-sourcing and will run that script in the current scope (i.e. the scope of your current script file). Thus, all functions that you define in myfunctions.ps1 will be defined after the beginning of your script file. Note that these functions won't be defined anymore once your script has ended. You can "load" your all functions that are defined script files at the interactive prompt in the same way. Example: ################# # myfunction.ps1 ################# function do-foo {"foo"} ################# ################# # myscript.ps1 ################# .. C:\mypath\myfunction.ps1 do-foo ################# -- greetings dreeschkind |
| | #4 (permalink) |
| Guest | Re: How to use function in other scriptfiles? Hello Roman "Roman Kuzmin" <RomanKuzmin@discussions.microsoft.com> schrieb im Newsbeitrag news:2F75C344-3D70-452A-A1C1-B81F59F94557@microsoft.com... > You have to "dot source" your script myfunctions.ps1 into another script > or > interactive session: > > . myfunctions.ps1 > > Now you may use functions from myfunctions.ps1. > As i understand your post I renamed the file "myfunctions.ps1" into ".myfunction.ps1" is this correct? The file ist saved in a normal folder like G:\myscripts\. in this folder the calling script is saved, too. If i want now to call the function getpfad() within the ..myfunctions.ps1-file, how can I call them? I dont find a way. ..myfunctions.ps1.getpfad() don't works G:\myscripts\.myfunctions.ps1.getpfad() don't works, too with best regards, Jens |
| | #5 (permalink) |
| Guest | Re: How to use function in other scriptfiles? thank you, now i understood. works fine. Jens "dreeschkind" <dreeschkind@discussions.microsoft.com> schrieb im Newsbeitrag news:2ED361B5-7615-4EDC-8BE1-206DBBA58ED2@microsoft.com... > "Jens Schulze" wrote: > >> Hello >> is it possible to run a function or scriptblock in another scriptfile? >> for >> example i have a script "myfunctions.ps1" with some functions and >> scriptblocks which i often use. now i wish to run in another script a >> defined function in "myfunction.ps1". >> >> with best regards Jens >> > > Put all script files that contain the functions you need at the beginning > of > your script and put a dot "." and a space infront of it. This is called > "dot"-sourcing and will run that script in the current scope (i.e. the > scope > of your current script file). Thus, all functions that you define in > myfunctions.ps1 will be defined after the beginning of your script file. > Note > that these functions won't be defined anymore once your script has ended. > You > can "load" your all functions that are defined script files at the > interactive prompt in the same way. > > Example: > > ################# > # myfunction.ps1 > ################# > function do-foo {"foo"} > ################# > > > ################# > # myscript.ps1 > ################# > . C:\mypath\myfunction.ps1 > > do-foo > ################# > > -- > greetings > dreeschkind |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can I get two variables out of a function? | ssg31415926 | PowerShell | 6 | 04-20-2008 07:29 AM |
| How can I tell if a function is already defined? | Kevin Buchan | PowerShell | 3 | 02-06-2008 07:50 AM |
| Function - XML | NeilOz | PowerShell | 4 | 01-10-2008 02:51 AM |
| possible function bug? | klumsy@xtra.co.nz | PowerShell | 1 | 09-29-2006 06:02 PM |
| BUG: Redirecting function contents to a file truncates function lines at the width of the console | Adam Milazzo | PowerShell | 2 | 08-11-2006 10:58 PM |