Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

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

Reply
 
Old 09-13-2006   #1 (permalink)
Brandon Shell


 
 

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]


 
 

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]


 
 

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


 
 

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
Reply

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


Vista Forums 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 Ltd

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