![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | How to - named function in script file Ok, I had now 3 days playing with PS. Played with all the cmdlets, piped here and there. One thing I can't accomplish is to put even the simplest function into a script file, load and finally use it. What I've done: * edited in an editor > function test-me { "outtestme" } > * saved as test-me.ps1 * in PS : cd <path> * in PS : ./test-me Got a prompt without error (expected to have the function defined now) * in PS : test-me get 'Test-me' is not recognized as a cmdlet, function, operable program, or script file. At line:1 char:7 + Test-me <<<< Where is the trick? Thanks, Thomas |
My System Specs![]() |
| | #2 (permalink) |
| | RE: How to - named function in script file "Thomy Kay" wrote: You would have to dot-source the file into the currently executing powershell session [^_^]PS[110]+>. .\test-me.ps1 [^_^]PS[111]+>test-me outtestme > Where is the trick? The trick is the dot, "." ![]() -- Sung M Kim Please don''t bother me with spam... |
My System Specs![]() |
| | #3 (permalink) |
| | Re: How to - named function in script file The other thing you can do is to define a global function in the script like: function global:foo { "Hi there" } -bruce -- Bruce Payette [MSFT] Windows PowerShell Technical Lead Microsoft Corporation This posting is provided "AS IS" with no warranties, and confers no rights. Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scr.../hubs/msh.mspx "Thomy Kay" <thomy.kay@online.de> wrote in message news:uBBHRE4wGHA.560@TK2MSFTNGP05.phx.gbl... > Soo easy! Anyway, you have to know it. Thanks! > > Thomy > > Sung M Kim wrote: >> "Thomy Kay" wrote: >> >> You would have to dot-source the file into the currently executing >> powershell session >> >> [^_^]PS[110]+>. .\test-me.ps1 >> [^_^]PS[111]+>test-me >> outtestme >> >>> Where is the trick? >> >> The trick is the dot, "." ![]() >> |
My System Specs![]() |
| | #4 (permalink) |
| | Re: How to - named function in script file Soo easy! Anyway, you have to know it. Thanks! Thomy Sung M Kim wrote: > "Thomy Kay" wrote: > > You would have to dot-source the file into the currently executing > powershell session > > [^_^]PS[110]+>. .\test-me.ps1 > [^_^]PS[111]+>test-me > outtestme > >> Where is the trick? > > The trick is the dot, "." ![]() > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Where can I put function in script? | PowerShell | |||
| 'Write-object' is not recognized as a cmdlet, function, operable program, or script file | PowerShell | |||
| Script-Function Help | PowerShell | |||
| BUG: Redirecting function contents to a file truncates function lines at the width of the console | PowerShell | |||
| Collecting named arguments in a script? | PowerShell | |||