![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | HowTo: Remove a .Dot Source Script from current environment? Can you do this? How? (and I dont mean restart psh ) |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: HowTo: Remove a .Dot Source Script from current environment? There's no direct way to do that. It's possible to approximate _somewhat_ with crude techniques such as reloading the config script, but in general this is a bit like trying to un-scramble an egg: not a good idea. You're better off throwing it away if you need to do more than remove a shell fragment. "Brandon Shell" <tshell.mask@gmail.com> wrote in message news:%23cee2M01GHA.3656@TK2MSFTNGP04.phx.gbl... > Can you do this? How? (and I dont mean restart psh )> |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: HowTo: Remove a .Dot Source Script from current environment? When you define variables, aliases, and functions, they get populated by default in the local scope. If you dot-source from a script, they go away when the script exits. If you dot-source from the regular command line, they go away when PowerShell exits. If you want to contain these changes so that you can still revert them from the command line, you need to ensure that the "Local Scope" is not the scope for the entire shell. So, you define them in a new scope. Jeffrey's blog on topic that includes the Start-NewScope function is helpful for that: http://blogs.msdn.com/powershell/arc...25/583268.aspx -- Lee Holmes [MSFT] Windows PowerShell Development Microsoft Corporation This posting is provided "AS IS" with no warranties, and confers no rights. "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message news:O2aM8X01GHA.3464@TK2MSFTNGP03.phx.gbl... > There's no direct way to do that. It's possible to approximate _somewhat_ > with crude techniques such as reloading the config script, but in general > this is a bit like trying to un-scramble an egg: not a good idea. You're > better off throwing it away if you need to do more than remove a shell > fragment. > > > "Brandon Shell" <tshell.mask@gmail.com> wrote in message > news:%23cee2M01GHA.3656@TK2MSFTNGP04.phx.gbl... >> Can you do this? How? (and I dont mean restart psh )>> > > |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: HowTo: Remove a .Dot Source Script from current environment? We don't have an automatic way of doing this, however, you could easily create a function that removes all traces of the bits the script created. This is not a good solution, I know, but it is possible. I hope that someday we'll have a good answer here. # swallow-tail.ps1 # after ouroborus $CurrentModule = "utilityfunctions" function get-Function1 { "I'm function 1!" } function get-Function2 { "I'm function 2!" } function remove-utilityFunctions { rm variable:CurrentModule rm function:Get-Function1 rm function:Get-Function2 rm function:remove-utilityFunctions } PS> . swallow-tail PS> get-function1 I'm function 1! PS> get-function2 I'm function 2! PS> $currentmodule utilityfunctions PS> remove-utilityFunctions PS> remove-utilityFunctions The term 'remove-utilityFunctions' is not recognized as a cmdlet, function, operable program, or script file. Verify ry again. At line:1 char:23 + remove-utilityFunctions <<<< PS> $currentmodule -- -- James Truher [MSFT] Windows PowerShell Development Microsoft Corporation This posting is provided "AS IS" with no warranties, and confers no rights. "Brandon Shell" <tshell.mask@gmail.com> wrote in message news:%23cee2M01GHA.3656@TK2MSFTNGP04.phx.gbl... > Can you do this? How? (and I dont mean restart psh )> |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Call PS Script with Environment Variable in Path via Command Line | bsdz | PowerShell | 4 | 06-04-2008 09:29 AM |
| Current script special variable | Frank | PowerShell | 1 | 03-01-2007 04:37 PM |
| HowTo: Add a switch to function/filter/script | Brandon Shell | PowerShell | 5 | 12-31-2006 07:55 AM |
| HowTo: Convert Function to script | Brandon Shell | PowerShell | 3 | 12-03-2006 11:20 PM |
| HowTo: Create Windows Form without Stopping the Script from Processing | Brandon Shell | PowerShell | 7 | 09-15-2006 05:24 PM |