![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | 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) |
| | 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) |
| | 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) |
| | 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 | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: Parse current IP address into environment variables | VB Script | |||
| creating Environment variable during logon script | VB Script | |||
| HowTo: Add a switch to function/filter/script | PowerShell | |||
| HowTo: Convert Function to script | PowerShell | |||
| HowTo: Create Windows Form without Stopping the Script from Processing | PowerShell | |||