Saving History to Script

by Sep 23, 2011

PowerShell is all about trial and error, and when you want to save your interactive input to a script file, this is how it could be done:

Get-History -Count $MaximumHistoryCount | ForEach-Object { $_.CommandLine | Out-File $env:temp\myscript.ps1 -Append }

Next, open the script in an editor of choice and edit the script, keeping only the lines that proved to be useful:

notepad $env:temp\myscript.ps1

Note that $MaximumHistoryCount by default is set to 64, so you can only get the latest 64 commands. Increase the history buffer:

$MaximumHistoryCount = (32KB -1)

You can place this line in your profile script to automatically expand the history buffer when PowerShell starts.

Your function Get-BIOS works both locally and remotely. Only the parameters submitted by the user will actually be forwarded to Get-WmiObject.

Twitter This Tip!
ReTweet this Tip!