Blogroll

Search

Portable PowerShell for V3 Beta

April 25th, 2012 by Karl

We have released Portable PowerShell for V3 Beta. We have only gotten the 32bit version working so there is no 64 Bit, and also no ISE. We won’t be looking further into the issues we had with both until there is a next version of V3 whether its another CTP\Beta\Release Candidate or RTM. Also not all features may work. For instance I know that workflow doesn’t work. Many things do but we haven’t done a full feature comparison.

an important thing is if there are issues, don’t presume it’s a PowerShell V3 Bug, as it could be related to Portable PowerShell. Please do not submit bugs to Microsoft until you’ve validated them on real PowerShell.

You can go to www.portablepowershell.com and download it from there and also download the original Portable PowerShell that covers V1 and V2 both 32 and 64 bit, and also ISE.

or you can directly Download Portable PowerShell

image

Posted in Portable PowerShell, Powershell, PSV2, PSV3 | No Comments »

Did you know you can have “advanced functions” with filters too?

August 10th, 2011 by Karl

In PowerShell to make a function an advanced function you typically decorate it with [PSCmdletBinding()] or attach a [Parameter()] to it, and now you get the full features of cmdlets available to you. the $pscmdlet variable, ability to support –whatif and –confirm as well as the ability to have multiple parameter sets, and put validation conditions on parameters and various other “full featured citizen” cmdlet abilities.

I don’t know if you know but the standard cmdlet has 3 different blocks, Begin , Process and End, begin happens at the beginning, while Process every time the pipeline iterates, and end well at the end. To support pipelining you have to do everything in the process block. However instead of defining a function you can use the filter keyword which basically is an automatic function so instead of

function myfunc
{
  process { “hello pipeline object $_ “ }
}
1..10 | myfunc

you can simply do

filter myfilter
{
“hello pipeline object $_ “
}
1..10 | myfilter

well I wasn’t sure whether you could use “advanced functions” with the filter keyword but after a little experimenting apparently you can.

filter advancedfilter {
  param([parameter(valuefrompipeline=$true)]$InputObject)
  "hello from advanced filter pipeline object $InputObject"
   }
1..10 | advancedfilter

Posted in Powershell, PSV2 | No Comments »

Print-File Function

November 10th, 2009 by Karl

Here is a simple function that will ask the associated program to print any file you pass in. It can work with a file as a parameter, or multiple files. How well this works, especially with multiple files at a time, depends on the associated application, first whether it supports the print verb, and secondly how it handles it – more importantly how it handles opening many files at once. I haven’t yet been brave enough to try it on PDFs with adobe reader.

function print-file($file)
{
 begin  {
    function internal-printfile($thefile)
    {
        if ($thefile -is [string]) {$filename = $thefile }
        else {
                if ($thefile.FullName -is [string] ) { $filename = $THEfile.FullName }
             }
        $start = new-object System.Diagnostics.ProcessStartInfo $filename
        $start.Verb = "print"
        [System.Diagnostics.Process]::Start($start)
    } 

if ($file -ne $null) {
                $filespecified = $true;
                internal-printfile $file
            }
       }
process{if (!$filespecified) { write-Host process ; internal-printfile $_ } } 

}

@poshcode | download

Here you can pass in a path to the file , or a fileobject that you get as a response from get-childitem (dir)

Here are a few examples

#look recursively through a folder and print all word documents
dir *.doc -r | print-file 

#print one particular pdf file
print-file c:\downloads\myfile.pdf

Warning, this isn’t up to being a shrink wrapped deliverable. It doesn’t do any error handling, isn’t a nice V2 advanced function or anything, but that’s a beauty of PowerShell, you can just hack out something that fits your needs in a few minutes. With V2 parameter binding, this would be more elegant and actually simpler as i have to do some duplication of logic in my function to get it to work accepting the file both through the pipeline and as a parameter.

-Enjoy.

Posted in Powershell, PSV2, script | 2 Comments »

PowerShell ISE-Cream

February 5th, 2009 by Karl

A while back I threw together a few scripts to enhance PowerShell V2 ISE experience that added some PowerShell Analyzer like features . They were a natural fit as ISE (Intergrated Scripting Environment) is like a WPF-based stripped PowerShell Analyzer like with its multiple runspaces, editors, and immediate command area.

The extensibility model of ISE has caught on, and many people have been writing some great scripts adding hotkeys to do every what not you could imagine, so I’ve decided to start a codeplex project with the punny name “PowerShell ISE-Cream” . The Goal of this project is first to gather a huge variety of functionality that various people are willing to share, refactor it into production quality functions, with extensive error handling, and packaged in V2 Modules, and finally incorporate it in a way that users can easily turn on and off different features through a consistent configuration.

Right now however we are just going to gather whatever scraps there are, whether they conflict with each other or not, and anybody passionate about this can join the project, as we sculpt it hopefully into something both useful and beautiful.

Doug Finke has already joined the club with his Expand-Alias and Expand-CurrentAlias functions, and there are quite a few other functions that people i know are willing to share, so it should be good.

We’ll be brainstorming and deciding on a bunch of design issue, you can join the conversation on the first one in this discussion thread.

The PowerScripting Podcast tonight (Thursday 5th Feb 2009) will be talking about ISE. There should be a number of MVPs (including myself) and some PowerShell Team staff calling in. It Should be fun.

-Karl

Posted in Powershell, pscom, PSV2 | 1 Comment »

Tobias and Idera make PowerShellPlus 2.1 Beta Public.

February 3rd, 2009 by Karl

Well its been six months or more since our baby PowerShell Plus grew up, left home and moved in with Idera. Well its been progressing nicely, and we are happy to see the vision being fulfilled,nd even expanded, with a successful commercial product. Go Tobias – Go Idera.

Anyhow, I’m pretty much going to reblog the content from Tobias’s blog entry below. If you haven’t tried PS+ yet. I recommend wholeheartedly that you do. It really is about 3 generations and a couple of years ahead of anything else out there. Other vendors have only recently implemented “borrowed” features that have been in PowerShell Analyzer and PowerShell Plus since 2006.

http://powershell.com/cs/blogs/news/archive/2009/02/02/powershellplus-v2-1-beta-is-live.aspx

———————————————————

Exciting news! Effective immediately, PowerShellPlus v2.1 Beta is live and publicly available! Below you will find exciting information about an early look at what the PowerShellPlus team has been working on.

PowerShellPlus version 2.1 introduces several new and cool features focused on reducing the PowerShell learning curve, increasing the productivity of PowerShell development and exercising the capabilities of PowerShell 2.0. The new features include:

  • Code sharing – Enables you to leverage the wealth of scripts that reside in the PowerShell.com and PoshCode.org libraries. Increase your productivity by quickly and easily searching and grabbing the scripts from those libraries. You can also submit your own scripts to the PowerShell.com library directly from PowerShell Plus Editor
  • Visual Basic support – The PowerShell Plus Editor can now edit and run Visual Basic scripts
  • STA mode support – Enables you to produce pretty cool looking GUI’s with Windows Presentation Framework (WPF) using PowerShell 2.0.
  • PowerShell Assembly Detection – Gives the Learning Center an auto-upgrade path if PowerShell v2 CTP3 is detected and then displays the most up-to-date information
  • Learning Center Auto-Load – Makes searching for a request with a single match much easier to use since the topic will load automatically, saving extra keystrokes
  • Cmdlet parameter position – Shows you additional information in the code completion popup window about parameters including position and type
  • Console size overlay – Shows you the height and width of the Console when you resize it
  • Additional Sample Scripts - Active Directory, IIS 7.0 and MySQL
  • PowerShell v2 CTP3 Support – Including Block Comments and the $Profile variable

How to get the New Version

Use the link at the bottom of this page to download the installation package, but before you do please read the following disclaimers, warnings and other general portents of doom.

  • This software is a pre-release version and should not be deployed in a production environment. It will not work the way a final version of the software does. Features will change before the final release
  • If you already have a PowerShellPlus license we recommend that you install this version on another machine, but we do support an upgrade in place your production version.
  • If you upgrade your production version of 2.0 we will not overwrite any user customizations that have been made to PowerShellPlus but we do recommend you make a copy of the Sample scripts if you have modified them.
  • A list of the changes is provided in the Release Notes in the Installation Package.
  • This release is designed to provide the PowerShellPlus community with a preview of key features coming in 2.1 and to solicit feedback about them. This Technical Beta is not supported by the Idera Technical Support Team. Please visit the Beta Place: http://powershell.com/cs/forums/93.aspx

System Requirements

  • Microsoft Windows PowerShell Version 1 or Version 2 CTP2 or CTP3
  • Windows XP, Server 2003, Windows Vista, Server 2008, Windows 7

Installation Instructions

To install PowerShellPlus:

  1. Click the link at the bottom of this page and complete the download form
  2. An email will be sent with instructions on how to download the Beta.
  3. After downloading the Beta, unzip the contents of the Installer package.
  4. Read the Release Notes for late breaking information about the Beta.
  5. If you are upgrading from PowerShellPlus 2.0 make that you copy the Sample Scripts to another location, if you have modified them.
  6. Run the Setup.exe program to install PowerShellPlus 2.1.

Grab your copy now:

Download Here

For feedback, bug reports, suggestions and discussions regarding this beta release, please visit and use our Beta Place:

http://powershell.com/cs/forums/93.aspx

Enjoy!

-Tobias

Posted in Powershell, Powershell Plus, pscom, PSV2 | 1 Comment »

PowerShell Analyzer like execution hotkeys for PS CTP3 ISE.

January 3rd, 2009 by Karl

PowerShell CTP3 ISE – Integrated Scripting environment has inherited many ideas and features from PowerShell analyzer including multiple runspaces,editors, a smaller immediate input area and output pane, however it doesn’t have the output visualizers of PSA nor the super fast RTS like execution control of PSA.

However Microsoft in their wisdom has made ISE rather extensible through the $PSISE variable, and many people already have added some very cool functionality to ISE through these.

When I first demo’d what was then MSH analyzer to Microsoft back in the first few months of 2006, the feature that seemed to stand out the most to the team was the ability to select an area of code and just run that. Thankfully that level of execution control is now in ISE as F6, but I wanted more, so i’m going to share with you a script that build a few months ago to add a couple of features.

F7 run the current physical line.

this basically will run the line where the caret current is at.

Real Time Strategy like control.. CTRL 1 , CTRL 2 etc

This here allows you to use comments to create regions, then EXECUTE those regions with a simple hotkey. I use this extensively. Often i am working on building a function, so I edit the function, press Ctrl 1 to apply the function, then if that was successful, press Ctrl 2 , then maybe Ctrl 3 to run some tests to make sure my changes to the function are what i am expecting.

This gives me a great AGILITY , putting what Jeffery Snover calls the Admin Development Model , but which is really REPL(Repeat Evaluate, Print , Loop ) rediscovered, on agile steroids.

function invoke-caretline
{
invoke-expression $([Regex]::Split($psISE.CurrentOpenedFile.Editor.text,"`r`n" )[$psISE.CurrentOpenedFile.Editor.caretline-1])
}
$psISE.CustomMenu.Submenus.Add("Run single line", {invoke-caretline} ,  'f7')
function invoke-region([int] $num)
{
$ed = $psISE.CurrentOpenedFile.Editor
$lines = [Regex]::Split($ed.text,"`r`n" )
$foundfirst = -1
$foundlast = -1
for($count = 0;$count -le $lines.length-1;$count++)
 {
   if ($lines[$count].startswith("#region") -and $lines[$count].contains("@$num"))
   { $foundfirst = $count;break}
 }
 if($foundfirst -gt -1)
 {
 for ($count = $foundfirst; $count -le $lines.length-1;$count++)
    {
    if ($lines[$count].startswith("#endregion") )
   { $foundlast = $count;break}
    } 

 if ($foundlast -gt -1)
   {
     $torun = ""
     $lines[$foundfirst..$foundlast] | % { $torun+=$_ + "`r`n"}
     invoke-expression $torun
   }
 } 

}
 $psISE.CustomMenu.Submenus.Add("run region 1", {invoke-region 1 },  'ctrl+1')
 $psISE.CustomMenu.Submenus.Add("run region 2", {invoke-region 2 },  'ctrl+2')
 $psISE.CustomMenu.Submenus.Add("run region 3", {invoke-region 3 },  'ctrl+3')
 $psISE.CustomMenu.Submenus.Add("run region 4", {invoke-region 4 },  'ctrl+4')
 $psISE.CustomMenu.Submenus.Add("run region 5", {invoke-region 5 },  'ctrl+5') 

Script @ PoshCode: View Script | Download

Sometime I’ll wrap all this up into a module, and add other PowerShell Analyzer-like functionality such as running the current PARAGRAPH. So often in an earlier PSA, and in SQL Query Analyzer, i’m highlighting again and again the SAME paragraph query and running it over and over again. Being able to just run the current paragraph saves that time.

Technorati Tags: ,,,

Posted in Powershell, pscom, PSV2 | 6 Comments »