Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

HowTo: Remove a .Dot Source Script from current environment?

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 09-13-2006   #1 (permalink)
Brandon Shell
Guest


 

HowTo: Remove a .Dot Source Script from current environment?

Can you do this? How? (and I dont mean restart psh )



My System SpecsSystem Spec
Old 09-13-2006   #2 (permalink)
Alex K. Angelopoulos [MVP]
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 SpecsSystem Spec
Old 09-13-2006   #3 (permalink)
Lee Holmes [MSFT]
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 SpecsSystem Spec
Old 09-25-2006   #4 (permalink)
James Truher
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 SpecsSystem Spec
Closed Thread

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


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51