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

save cmdlets

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-31-2007   #1 (permalink)
Ryan
Guest


 

save cmdlets

Is there a way I can save cmdlets I have used in previous sessions? i.e. I
want to be able to enter cmdlets I have used in the past after I close and
restart PowerShell or after I reboot. These would be both for cmdlets I have
written (.ps1 files) & those I have not.

My System SpecsSystem Spec
Old 03-31-2007   #2 (permalink)
Joris van Lier
Guest


 

Re: save cmdlets

Ryan wrote:
> Is there a way I can save cmdlets I have used in previous sessions?
> i.e. I want to be able to enter cmdlets I have used in the past after
> I close and restart PowerShell or after I reboot. These would be
> both for cmdlets I have written (.ps1 files) & those I have not.


Yes you can using Export-Console, see
http://msdn2.microsoft.com/en-us/library/ms714644.aspx , notice there's a
bug: the exported console has a .psc1 extension not the .mcf extension the
docs mention
My System SpecsSystem Spec
Old 03-31-2007   #3 (permalink)
Joris van Lier
Guest


 

Re: save cmdlets

Ryan wrote:
> Is there a way I can save cmdlets I have used in previous sessions?
> i.e. I want to be able to enter cmdlets I have used in the past after
> I close and restart PowerShell or after I reboot. These would be
> both for cmdlets I have written (.ps1 files) & those I have not.


Sorry i misunderstood you, do you want to save and reload your history instead of the CmdLets (those are written in a .NET language like C#) and loaded via PSSnapIns?

You can save your history, for example in CliXML format, by piping the output of Get-History into Export-CliXml
PS> Get-History | Export-Clixml history.clixml
Reload the history by piping the output of Import-CliXml into Add-History
PS> Import-Clixml history.clixml | Add-History

You can "dot source" your ps1 files in your profile, see the docs for more info http://msdn2.microsoft.com/en-us/library/aa717060.aspx

Joris
My System SpecsSystem Spec
Old 03-31-2007   #4 (permalink)
Ryan
Guest


 

Re: save cmdlets

This gives me an onscreen text display of previous cmdlets used in the
previous session, but I want to actually b able to use these commands by
pressing the up and down arrows on the keyboard, not just see what cmdlets
were used.

"Joris van Lier" wrote:

> Ryan wrote:
> > Is there a way I can save cmdlets I have used in previous sessions?
> > i.e. I want to be able to enter cmdlets I have used in the past after
> > I close and restart PowerShell or after I reboot. These would be
> > both for cmdlets I have written (.ps1 files) & those I have not.

>
> Sorry i misunderstood you, do you want to save and reload your history instead of the CmdLets (those are written in a .NET language like C#) and loaded via PSSnapIns?
>
> You can save your history, for example in CliXML format, by piping the output of Get-History into Export-CliXml
> PS> Get-History | Export-Clixml history.clixml
> Reload the history by piping the output of Import-CliXml into Add-History
> PS> Import-Clixml history.clixml | Add-History
>
> You can "dot source" your ps1 files in your profile, see the docs for more info http://msdn2.microsoft.com/en-us/library/aa717060.aspx
>
> Joris
>

My System SpecsSystem Spec
Old 04-01-2007   #5 (permalink)
RichS
Guest


 

RE: save cmdlets

In other words you want a permanent record of the commands you have run so
that you can scroll through them in oder to rerun the commands. Afraid thats
not possible with base PowerShell. You can add functions to your profile to
make functionality avaialble but not in the way you want
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Ryan" wrote:

> Is there a way I can save cmdlets I have used in previous sessions? i.e. I
> want to be able to enter cmdlets I have used in the past after I close and
> restart PowerShell or after I reboot. These would be both for cmdlets I have
> written (.ps1 files) & those I have not.

My System SpecsSystem Spec
Old 04-01-2007   #6 (permalink)
Ryan
Guest


 

RE: save cmdlets

OK.
So what is the exact text I need to add to my profile file to make this
happen? Not finding any info on how to do so on your blog.

"RichS" wrote:

> In other words you want a permanent record of the commands you have run so
> that you can scroll through them in oder to rerun the commands. Afraid thats
> not possible with base PowerShell. You can add functions to your profile to
> make functionality avaialble but not in the way you want
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog: http://richardsiddaway.spaces.live.com/
> PowerShell User Group: http://www.get-psuguk.org.uk
>
>
> "Ryan" wrote:
>
> > Is there a way I can save cmdlets I have used in previous sessions? i.e. I
> > want to be able to enter cmdlets I have used in the past after I close and
> > restart PowerShell or after I reboot. These would be both for cmdlets I have
> > written (.ps1 files) & those I have not.

My System SpecsSystem Spec
Old 04-01-2007   #7 (permalink)
Keith Hill
Guest


 

Re: save cmdlets

"Ryan" <Ryan@discussions.microsoft.com> wrote in message
news:0AD68AE5-B901-4E3C-A861-7F5F118D755C@microsoft.com...
> Is there a way I can save cmdlets I have used in previous sessions? i.e.
> I
> want to be able to enter cmdlets I have used in the past after I close and
> restart PowerShell or after I reboot. These would be both for cmdlets I
> have
> written (.ps1 files) & those I have not.


You can save an entire record of your PowerShell session with the
Start-Transcript cmdlet. If you want certain functions to be part of your
global environment then create a profile (if you doesn't already exist):

if (!(Test-Path $profile)) { new-item -type file $profile }
notepad $profile

Then add your functions directly to this file. If you want your profile to
be more modular then you can put your PowerShell function in a PS1 file and
then dot source that file into your profile like so:

.. "$home\My Documents\WindowsPowerShell\funcs.ps1"

--
Keith

My System SpecsSystem Spec
Old 04-01-2007   #8 (permalink)
Keith Hill
Guest


 

Re: save cmdlets

"Keith Hill" <r_keith_hill@mailhot.nospamIdotcom> wrote in message
news:16F16F6D-F4CA-4652-B683-0D7E084814AD@microsoft.com...
> global environment then create a profile (if you doesn't already exist):


Oops. That should say "if *one* doesn't already exist". I know you exist
otherwise how would you be posting to this newsgroup. :-)

--
Keith

My System SpecsSystem Spec
Old 04-05-2007   #9 (permalink)
Ryan
Guest


 

Re: save cmdlets

I have a profile.ps1 file set up, but there are some things that I should let
you know of:
- I have 18+ yrs experience with computers, but I am not as familiar w/ the
areas of programming and networking. (I understand this issue doesen't
involve networking.)
- I don't know what the terms "global environment" and "modular" mean.
- I think "session" means the timeframe during which I start and close
powershell; during which time powershell already saves whichever cmdlets I
have used.

I'm sure you already understand this, but what I'm looking for is to be able
to reuse any cmdlet I have used previously in powershell from the point at
which I make the change I need to make forward.

1:
So, do I need to put the following text into my existing profile:
if (!(Test-Path $profile)) { new-item -type file $profile }
> notepad $profile

and, if so, does it matter where in the profile the text is placed?

2:
What are functions and where within the profile do I add them? (I assume
that "functions" are cmdlets that I have written).

3:
If you want your profile to
> be more modular then you can put your PowerShell function in a PS1 file and
> then dot source that file into your profile like so:
>
> . "$home\My Documents\WindowsPowerShell\funcs.ps1"


Where do I put the above text at & what is dot sourcing and how do I do it?



"Keith Hill" wrote:

> "Ryan" <Ryan@discussions.microsoft.com> wrote in message
> news:0AD68AE5-B901-4E3C-A861-7F5F118D755C@microsoft.com...
> > Is there a way I can save cmdlets I have used in previous sessions? i.e.
> > I
> > want to be able to enter cmdlets I have used in the past after I close and
> > restart PowerShell or after I reboot. These would be both for cmdlets I
> > have
> > written (.ps1 files) & those I have not.

>
> You can save an entire record of your PowerShell session with the
> Start-Transcript cmdlet. If you want certain functions to be part of your
> global environment then create a profile (if you doesn't already exist):
>
> if (!(Test-Path $profile)) { new-item -type file $profile }
> notepad $profile
>
> Then add your functions directly to this file. If you want your profile to
> be more modular then you can put your PowerShell function in a PS1 file and
> then dot source that file into your profile like so:
>
> . "$home\My Documents\WindowsPowerShell\funcs.ps1"
>
> --
> Keith
>

My System SpecsSystem Spec
Old 04-05-2007   #10 (permalink)
Ryan
Guest


 

Re: save cmdlets

Also, I forgot:
I'm a home user, not a programmer or admin, but I do consider myself to be a
poweruser.
I use XP Home, P4 2.66 w/ 1.5 GB RAM. Not the greatest n the world, but not
bad either.


"Keith Hill" wrote:

> "Ryan" <Ryan@discussions.microsoft.com> wrote in message
> news:0AD68AE5-B901-4E3C-A861-7F5F118D755C@microsoft.com...
> > Is there a way I can save cmdlets I have used in previous sessions? i.e.
> > I
> > want to be able to enter cmdlets I have used in the past after I close and
> > restart PowerShell or after I reboot. These would be both for cmdlets I
> > have
> > written (.ps1 files) & those I have not.

>
> You can save an entire record of your PowerShell session with the
> Start-Transcript cmdlet. If you want certain functions to be part of your
> global environment then create a profile (if you doesn't already exist):
>
> if (!(Test-Path $profile)) { new-item -type file $profile }
> notepad $profile
>
> Then add your functions directly to this file. If you want your profile to
> be more modular then you can put your PowerShell function in a PS1 file and
> then dot source that file into your profile like so:
>
> . "$home\My Documents\WindowsPowerShell\funcs.ps1"
>
> --
> Keith
>

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Save Energy, Save Space in Hard Disk? vbahamondes Vista performance & maintenance 2 01-25-2008 12:58 PM
Outlook 2007 won't save passwords in Vista...save password box che Craig Vista account administration 10 11-16-2007 02:51 PM
Open/Save/Save As dialogue shortcuts @ndyB Vista General 9 03-16-2007 01:58 PM
Programs using Open, Save, Save As functions Stop Responding Louie1214 Vista performance & maintenance 2 03-06-2007 12:51 AM
Office 2007 hangs on Save and Save As GlennS Vista General 8 02-05-2007 12:51 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