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 - HOW TO: Can you Reload Profiles without restarting POSH?

Reply
 
Old 08-17-2006   #1 (permalink)
Brandon Shell


 
 

HOW TO: Can you Reload Profiles without restarting POSH?




My System SpecsSystem Spec
Old 08-17-2006   #2 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: HOW TO: Can you Reload Profiles without restarting POSH?

Use this to re-source the profile script:
.. $PROFILE
Note that if you add custom type data in your profile through an
Update-TypeData command, you will not be able to reload types that have been
modified, and the Update-TypeData command will generate errors.

"Brandon Shell" <tshell.mask@gmail.com> wrote in message
news:OJZmLLkwGHA.2400@TK2MSFTNGP06.phx.gbl...
>
>



My System SpecsSystem Spec
Old 08-17-2006   #3 (permalink)
Keith Hill [MVP]


 
 

Re: HOW TO: Can you Reload Profiles without restarting POSH?

"Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
news:%23$oDclkwGHA.3420@TK2MSFTNGP04.phx.gbl...
> Use this to re-source the profile script:
> . $PROFILE
> Note that if you add custom type data in your profile through an
> Update-TypeData command, you will not be able to reload types that have
> been modified, and the Update-TypeData command will generate errors.


You can work around that problem like so:

$global:__profileLoadCount += 1
if ($global:__profileLoadCount -eq 1) {
# Do first time only stuff here
}

--
Keith


My System SpecsSystem Spec
Old 08-17-2006   #4 (permalink)
=?Utf-8?B?Um9tYW4gS3V6bWlu?=


 
 

Re: HOW TO: Can you Reload Profiles without restarting POSH?

"Alex K. Angelopoulos [MVP]" wrote:
>...


I was waiting for a thread like this

My $PROFILE variable contains
“C:\Documents and Settings\rom\My
Documents\PSConfiguration\Microsoft.PowerShell_profile.ps1”

but there is no such a file; my profile is
"C:\Documents and Settings\rom\My Documents\PSConfiguration\profile.ps1”

What does that mean?

And therefore your suggestion will not work for me.

--
Thanks,
Roman

My System SpecsSystem Spec
Old 08-17-2006   #5 (permalink)
Brandon Shell


 
 

Re: HOW TO: Can you Reload Profiles without restarting POSH?

Glad I could help

btw... I have the same problem:

PS C:\> $profile
C:\Documents and Settings\Bloomberg User\My
Documents\PSConfiguration\Microsoft.PowerShell_profile.ps1
PS C:\>

"Roman Kuzmin" <RomanKuzmin@discussions.microsoft.com> wrote in message
news:CF08B3DC-C785-406D-A876-578288B79BD7@microsoft.com...
> "Alex K. Angelopoulos [MVP]" wrote:
>>...

>
> I was waiting for a thread like this
>
> My $PROFILE variable contains
> "C:\Documents and Settings\rom\My
> Documents\PSConfiguration\Microsoft.PowerShell_profile.ps1"
>
> but there is no such a file; my profile is
> "C:\Documents and Settings\rom\My Documents\PSConfiguration\profile.ps1"
>
> What does that mean?
>
> And therefore your suggestion will not work for me.
>
> --
> Thanks,
> Roman
>



My System SpecsSystem Spec
Old 08-17-2006   #6 (permalink)
Fred Jacobowitz


 
 

Re: HOW TO: Can you Reload Profiles without restarting POSH?

Let me give this a shot. Prior to RC1 I believe the filename for the
profile was profile.ps1 .
It has been changed to Microsoft.PowerShell_profile.ps1
Therefore, you need to change the name of your 'profile' profile.

Fred Jacobowitz


"Roman Kuzmin" <RomanKuzmin@discussions.microsoft.com> wrote in message
news:CF08B3DC-C785-406D-A876-578288B79BD7@microsoft.com...
> "Alex K. Angelopoulos [MVP]" wrote:
>>...

>
> I was waiting for a thread like this
>
> My $PROFILE variable contains
> "C:\Documents and Settings\rom\My
> Documents\PSConfiguration\Microsoft.PowerShell_profile.ps1"
>
> but there is no such a file; my profile is
> "C:\Documents and Settings\rom\My Documents\PSConfiguration\profile.ps1"
>
> What does that mean?
>
> And therefore your suggestion will not work for me.
>
> --
> Thanks,
> Roman
>



My System SpecsSystem Spec
Old 08-17-2006   #7 (permalink)
=?Utf-8?B?Um9tYW4gS3V6bWlu?=


 
 

Re: HOW TO: Can you Reload Profiles without restarting POSH?

"Fred Jacobowitz" wrote:
> Let me give this a shot. Prior to RC1 I believe the filename for the
> profile was profile.ps1 .
> It has been changed to Microsoft.PowerShell_profile.ps1
> Therefore, you need to change the name of your 'profile' profile.


User Guide for RC1:

How the Shell Starts
The files are run in the following sequence:
Documents and Settings\All Users\Documents\PSConfiguration\Profile.ps1
Documents and Settings\All
Users\Documents\PSConfiguration\Microsoft.PowerShell_Profile.ps1
$HOME\My Documents\PSConfiguration\profile.ps1
$HOME\My Documents\PSConfiguration\Microsoft.PowerShell_profile.ps1

I use this (and it is loaded, sure!):
$HOME\My Documents\PSConfiguration\profile.ps1

The question is: why $PROFILE contains not existing path
$HOME\My Documents\PSConfiguration\Microsoft.PowerShell_profile.ps1?

--
Thanks,
Roman

My System SpecsSystem Spec
Old 08-18-2006   #8 (permalink)
=?Utf-8?B?Um9tYW4gS3V6bWlu?=


 
 

Re: HOW TO: Can you Reload Profiles without restarting POSH?

I have found an interesting related blog post of Lee Holmes here:
http://www.leeholmes.com/blog/TheSto...lProfiles.aspx

Answers are there.

--
Thanks,
Roman

My System SpecsSystem Spec
Old 08-18-2006   #9 (permalink)
Brandon Shell


 
 

Re: HOW TO: Can you Reload Profiles without restarting POSH?

So effectively I have to rename my profile.ps1 to
Microsoft.PowerShell_Profile.ps1? Just so I can reload it?

"Roman Kuzmin" <RomanKuzmin@discussions.microsoft.com> wrote in message
news:998DA24C-0ACF-4E31-A03B-5FB3B27573F5@microsoft.com...
>I have found an interesting related blog post of Lee Holmes here:
> http://www.leeholmes.com/blog/TheSto...lProfiles.aspx
>
> Answers are there.
>
> --
> Thanks,
> Roman
>



My System SpecsSystem Spec
Old 08-18-2006   #10 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: HOW TO: Can you Reload Profiles without restarting POSH?

"Brandon Shell" <tshell.mask@gmail.com> wrote in message
news:eIuOzzswGHA.428@TK2MSFTNGP03.phx.gbl...
> So effectively I have to rename my profile.ps1 to
> Microsoft.PowerShell_Profile.ps1? Just so I can reload it?


Not really. Here's the loooong answer I avoided earlier...

I assume you really want to be able to "freshen" function definitions and
such, but don't want to lose command history or current variables in the
shell. For various reasons - time available, some limits of .NET that need
to be handled with proper solutions, etc - there's no specific tool
implemented to allow reset. However, it's possible to write an Update-Me
function that handles all of this stuff in a system-independent fashion.

Basically, you have two profile scripts based on intent: profile.ps1 will be
used by any application that uses the PowerShell framework in general, and
Microsoft.PowerShell_Profile.ps1 that PowerShell version 1 itself. The
generic profile.ps1 script is loaded first so that host-specific changes can
override it.
These are loaded from the PSConfiguration folder within the all user
documents and the current user documents folder. All we need to do is set up
a function to determine the path to each of these folders, then assemble the
4 script paths and test each one, executing the named script in the correct
order.

The following wrapper script generally does this. Notice that it kills all
of the variables it uses when it is finished. You need to "." invoke it:
.. Restart-PsProfile


function Restart-PsProfile()
{
$__sa = New-Object -ComObject Shell.Application
$__Files = "profile.ps1",`
"Microsoft.PowerShell_profile.ps1"
$__Locations = ($__sa.Namespace(0x2e).Self.Path),`
($__sa.Namespace(5).Self.Path)
foreach($__Location in $__Locations)
{
$__Location = Join-Path $__Location PSConfiguration
foreach($__File in $__Files)
{
$__File = Join-Path $__Location $__File;
if(Test-Path $__File){. $__File}
}
}
Remove-Variable -Name `
__File,__Files,__Location,__Locations,__sa
}




My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Is there a way to reload Windows Vista Ultimate upgrade without having to reload XP? General Discussion
Vista Reload--HELP!! General Discussion
Re-Format and Reload? Vista installation & setup
System Reload... x32 or x64? Gaming
Can I have two workgroup profiles and change without restarting??! Vista networking & sharing


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