Handy little function: Create-Script

One of the great features of Windows Powershell is the combination of the rich scripting language and the interactive shell. I often find myself playing around in the interactive shell until I know how to get the information I need. Then I start to put the code into a script for easy use. (And to share it with you, of course.) And although the shell allows for copy/paste, I wouldn’t be much of a scripting enthusiast if I didn’t want that to be easier 😉
Enter Create-Script. This little function belongs in any scripter’s profile. It copies your entire history into a file and opens it for you. Just remove the obsolete lines and add formatting and comment and your script is as good as done!

function Create-Script
$ScriptFile = ‘D:\scripts\newscript.ps1’
Remove-Item $ScriptFile -Confirm
ForEach ($i in (Get-History -Count 999))
Add-Content $ScriptFile $i.CommandLine
Invoke-Item $ScriptFile

The function re-uses the same file each time, asking for confirmation to overwrite it. Don’t forget to use Save As… to store your finished work.

I can’t wait to see the masterpieces you will create. Don’t forget to share them!

PS: You might want to consider to increase the amount of commands kept in your history. Just set the $MaximumHistoryCount variable to the desired value.

Determined that this would be the last such revolt, Crassus had all 6,000 of them crucified along the Appian Way, which went from Rome to Capua. “It could be,” Sanders responded. You can do one or both, alternating, but you want to make sure that whenever you’re doing a bicep curl your chest stays upright, your stomach stays drawn in to the space, and you try to keep your shoulders back. Seventeen individuals have played more than 300 first grade games. ISIS has in part succeeded at taking over the local economies because the people of Iraq and wholesale football jerseys Syria are simply disgusted with the rampant government corruption they’ve witnessed, said Brian Katulis, a senior fellow at the left leaning Center for American Progress. Ragland is a smart player who takes good angles to the ball, which http://www.cheapjordan13.com mitigates cheap ray bans his lack of speed against the run, but he will not able to hold up oakleys outlet in pass coverage at the next level. Seeing NFL Jerseys China the opportunity it presented, she grabbed and ran with it seeking to find out where it would lead her. And the House Un American Activities Committee cheap nfl jerseys had blacklisted both men. What is worrisome about Centerra is the pressure to nationalize Kumtor seems to have reached a fever pitch oops wrong kind of football. Los arquitectos an no han dicho si contar con indicaciones de colores similares si dos o ms equipos fueran los anfitriones de los partidos en el nuevo estadio en Inglewood.. They’re 6 2 against Manning in his career.Coach Mike Zimmer was concerned about Beckham, Victor Cruz and Sterling Shepard, as dangerous a trio of pass catchers as there is in the NFL, so the Vikings didn’t blitz the Giants (2 2) nearly as much as they did Rodgers’ Packers or Newton’s Panthers.”It just shows our versatility,” linebacker Anthony Barr said.Sam Bradford threw a touchdown pass to tight end Kyle Rudolph for the third straight game and kept his turnover free streak since joining the Vikings intact, and Matt Asiata and Jerick McKinnon each ran for a touchdown as part of a season high 104 yards rushing for the team. Aside from the worrying implication that we might all be dicks, there’s another problem: Processing sarcasm uses up precious brainpower. You are a bunch of morans that don even deserve to utter his name from your mouths. 1) Mad Catz Interactive (NYSEMKT:MCZ) They are in the gaming industry and sell different products for certain games and http://www.ray-banbaratas.top computers. It went with Bane, a genius hulk with a booming voice immune to bat punches, bat gadgets, and all forms of darkness. Jones replaced Vick on Sunday and was 8 of 12 passing for 168 yards and two touchdowns.Here are the other notable injuries from Week 6in the NFL: Denver Broncos wide receiver Emmanuel Sanders has a sprained AC joint, NFL Network reported.

2 thoughts on “Handy little function: Create-Script”

  1. Very cool function! I would always just re-type this stuff as needed. I love this!

    I did modify a couple of things in mine.

    – Rather than Invoke-Item, I am using: $psplus.OpenFile($scriptFile)

    This guarantees that the script file open in my PowerShellPlus editor.

    – I am overwriting the temp script file like this:
    if (test-path $scriptFile) {Remove-Item $scriptFile -force}

    This prevents an error from showing up if the file does not exist. Also, it forces the overwrite, which I prefer.

    Great little tool! Thank you for sharing it.

Leave a Reply