Sonntag, 25. Oktober 2009

Hello ISEpack

Hello PowerSheller Users,
now that Windows 7 is available and the most important event of the year PowerShell v2 Virtual Launch Party is history and James Brundage has buried as under tons of new functions in the PowerShell Pack
hopefully the last installations of PowerShell V2 CTP are replaced by the V2 RTM or V2 RC if you have a downgrade system.

ISE the Integrated Scripting Environment provides Windows conform copy & paste shortcuts. Thanks.

Any case, if you are completely new to PowerShell, it is better if you start with some GUI tool perhaps the free PowerGui or the commercial PowerShell Plus v3.0 , which have a lot of Intellisense build in. If you are interessted inother alternatives I recommend install Shay Levy's PowerShell Toolbar
. The link to the download is a little hidden, just above the comment section. Then go to resources | Script Editors.

These tools are kind of studios. They have some start-up time additional to that caused by your profile scripts and they try to help you in avoiding making mistakes by adding intellisense.

ISE is somewhat other. When you start it for the first time and scan through its menus you get the strong impression that there is something missing. For example: print, recently used files, ....

You are right, but there is something you don't see until you run some suitable script or import a module. ISEPack from the PowerShell Pack is one of these Modules:

import-module isepack

Afterwards the Add-ons menu appears. That is the magic location where you can extend ISE with all kinds of things you can sensibly do. And even some more.

There is an older Code Plex Project PowerShell ISE-Cream
which stagnated the last month due to PowerShell V2 CTP3 - V2 incompatibilities. I hope we will come back to life now.

My advice is please study ISEpack first and try ISE-Cream later. ISE-Cream is open and you too can contribute.

But now let us explore ISEPack a bit.

pushd "$(split-path $profile)\modules\isepack"         
Get-ChildItem


The most important file here is IsePack.psm1 . Here you find the code that constructs the add-ons menu.

You have qualms to modify JB's code.

No problem, you leave it as it is and add to the menu in another script:

Add-IseMenu -Name "My Extensions" @{                      
"Save File AS ANSI" = { $psISE.CurrentFile.Save([Text.Encoding]::default) } |
Add-Member NoteProperty ShortcutKey "ALT+Shift+A" -PassThru
}

Please note that I use default here and not ascii. Ascii is 7-bit only an not suitable for the german and many other western European languages.

Damned I forgot to take my chance at the launch party to ask Jeffrey, why there is a value called default, which isn't used by default.

I hope this helps to take the very first steps into the word of ISE Extensions.

Bernd

Freitag, 16. Oktober 2009

Testing Copy-ColoredHTML

Just testing PowerShell Pack isePack. Copy-ColoredHTML.
http://blogs.msdn.com/powershell/archive/2009/10/15/introducing-the-windows-7-resource-kit-powershell-pack.aspx

It follows my disk free version. I'm using mounted volumes and I have to watch for free space on my partitions.

$outData = @("")           
$server = $args[0]
$dataFromServer = Get-WmiObject Win32_Volume -ComputerName '.' | Select-Object SystemName,Label,Name,DriveLetter,DriveType,Capacity,Freespace


# Formatting
$size = @{ l = "Size (GB)"; e = { $_.Capacity/1gb}; f = "{0:0.0}"}
$free = @{ l = "free (GB)"; e = { $_.Freespace/1gb}; f = "{0:0.0}"}
$perc = @{ l = "percent"; e = { 100.0 * ([double]$_.freespace/[double]$_.Capacity)}; f="{0:00.0}" }
$name = @{ e = "Label"; f = "{0,-10}" }
$fields = $name,$size,$free,$perc

foreach ($currline in $dataFromServer) {
if ((-not $currline.name.StartsWith("\\")) -and ($currline.Drivetype -ne 5)) {
[float]$tempfloat = ($currline.Freespace / 1000000) / ($currline.Capacity / 1000000)
$temppercent = [math]::round(($tempfloat * 100),2)
add-member -InputObject $currline -MemberType NoteProperty -name FreePercent -value "$temppercent %"
$outData = $outData + $currline
}
}

$outData | sort-object -property Label | format-table $fields -auto
# Select-Object Label,Capacity,Freespace, FreePercent
#| sort-object -property FreePercent | format-table -autosize



# http://mspowershell.blogspot.com/2007/12/script-to-extract-disk-space-usage.html
# http://jtruher.spaces.live.com/blog/cns!7143DA6E51A2628D!138.entry