background preloader

HuddledMasses

Facebook Twitter

Huddled Masses » Blog Archive » PowerBoots: The tutorial walkthrough. Updated to PowerBoots 0.1 An introduction to PowerBoots Please excuse me if I start by just copying the basic ideas of the Shoes Tutorial, but I figured that since PowerBoots is inspired by Shoes, that was as good a place as any to start.

Huddled Masses » Blog Archive » PowerBoots: The tutorial walkthrough

PowerBoots (or just “Boots”) is a PowerShell 2.0 module with functions for writing Windows Presentation Framework (WPF) applications in the PowerShell scripting language. You should get the latest version of PowerBoots before continuing, and install it by putting the “PowerBoots” folder in one of your “Modules” folders (list them by typing $Env:PSMODULEPATH in PowerShell v2). Don’t forget to start PowerShell.exe with the STA parameter (This is no longer required in PowerBoots 0.1). Did I hear someone ask what is WPF? A simple Boots program New-BootsWindow -SizeToContent WidthAndHeight -Content { Button -Content "Push Me" } New-BootsWindow -SizeToContent WidthAndHeight -Content ( Button -Content "Push Me") Boots { Button "Push Me" } StackPanels are awesome. Huddled Masses » Blog Archive » PowerBoots: Loading XAML Windows in PowerShell 1.0 or 2.0.

Awhile back I wrote a series of posts about WPF From PowerShell From PowerShell” which were about how you could load XAML in previous PowerShell 2 CTPs to create WPF user interfaces … a few people have mentioned loading XAML in PowerBoots, and a couple of people have posted other samples showing XAML even since I published the most recent release, so I figure it’s time to point out that you really can load that XAML into Boots, and get all the threading and other support. Just for fun, I’m going to rehash an earlier post about updating windows to show how you can go about this using PowerBoots, and hopefully show that it’s a little easier (and a lot more async). Compare and contrast the code in this article with that one, just for fun. This works with any version of PowerShell The simple splash screen. Huddled Masses » Blog Archive » PowerShell Module Manifests Tip: allowed cmdlets and variables.

I was under the impression that module manifests allow only DATA stuff.

Huddled Masses » Blog Archive » PowerShell Module Manifests Tip: allowed cmdlets and variables

In fact, if you try to use cmdlets or variables in them, you get the usual Data-language errors, like this: Import-Module : The module manifest ‘C:\Modules\Test\Test.psd1’ could not be processed because it is not a valid PowerShell restricted language file. Please remove the elements that are not permitted by the restricted language: The command ‘Get-ChildItem’ is not in allowed in restricted language mode or a Data section. Huddled Masses » Blog Archive » RFC: Information in PoshCode Module Manifests. OK, I’m putting this out there to see if I’ve missed anything that would be useful.

Huddled Masses » Blog Archive » RFC: Information in PoshCode Module Manifests

This is the list of metadata that we’ll be storing about Modules in the PoshCode repository. It duplicates most of the information in the PowerShell Manifests, but it adds more of information that we feel is important for searching, sorting and organizing … and in the PoshCode Module manifests, wildcards are not allowed for any of the “export” values. The export information in the module is intended to represent the initial state of the module after import: listing all the cmdlets, functions, variables and aliases … PoshCode Module Manifest Format: The globally unique identifier for this module.

Name The name of this module. ModuleVersion The version of this module. Description A short description of the module. ModuleType. Huddled Masses » Blog Archive » What’s new in PowerShell 2? Huddled Masses » Blog Archive » PowerBoots (Next Generation UI) WPF for PowerShell slides. Huddled Masses » Blog Archive » More Custom Attributes for PowerShell (Parameter Transformation) I wrote a post awhile back about using custom attributes for PowerShell parameter validation but when I did it, I focused on the use of attributes to improve the error messages output by validation (specifically, by: ValidatePattern).

Huddled Masses » Blog Archive » More Custom Attributes for PowerShell (Parameter Transformation)

There are many other things that can be done with custom attributes. However, PowerShell ships with two base types for attributes which derive from the CmdletMetadataAttribute, and it applies special processing to parameters of functions or cmdlets which have these attributes: ValidateArguments and ArgumentTransformation, since I’ve already written about custom argument validation, I figured a post about argument transformations would be appropriate. Exporting Functions in PowerShell Modules. December 16, 2008 at 1:12 AM — Andy Schneider Modules in PowerShell, among other things, will allow code to be shared very easily within a community.

Exporting Functions in PowerShell Modules

One of the issues with scripts and dot sourcing right now is that we end up polluting our working session with a lot of variables and functions that we don't really need. These are helper functions and helper variables that are used by larger functions. Huddled Masses » PowerShell. Huddled Masses » Blog Archive » PowerShell Scripting Best Practices: Prefix A. I’m starting a new series of blog posts about Best Practices for scripting in PowerShell, and I was going to start at the beginning with a requirement that you should use [CmdletBinding()], but the explanation of that will have to wait for the next post, because a bug in PowerShell 2.0 has surfaced which can only be avoided by carefully following a couple of rules … and I’m going to issue those rules as the prefix for the best practices.

Huddled Masses » Blog Archive » PowerShell Scripting Best Practices: Prefix A

Rule #1: Never use Get-Module -ListAvailable in a module. You need to run the command outside of your module. The simplest way to do that is to use Invoke-Command { Get-Module -List Available } … that should give you the same output, but without the nasty side effects. Huddled Masses » Blog Archive » Another Module Manifest Gotcha. Shay Levy, ScriptFanatic, wrote about the PowerShellHostVersion on his blog this morning, explaining how it is not a field you should use in your module manifests. Of course, there’s an exception: if your module is dependent on a specific host.

For instance, if you’ve written a module for PoshConsole which exploits the WpfHost display features or the BgHost hotkeys feature … or if you’ve written ISEPack based on the menu and script-editor features of PowerShell ISE), then it makes sense to specify the PowerShellHostName and the PowerShellHostVersion together. Huddled Masses » Blog Archive » PowerBoots and Attached Properties. WPF uses a concept called “Attached Properties” to handle certain things, like when you put controls into a DockPanel.

Huddled Masses » Blog Archive » PowerBoots and Attached Properties

Basically, anything you put inside a DockPanel has a property “Dock” which you can set … but because the property is actually defined by the DockPanel, it doesn’t show up in PowerBoots, so you can’t just say -Dock "Bottom" when you create the child items … at least, not yet. I’m still thinking about the best way for me to expose this in PowerBoots, because the problem is that attached properties can get attached several ways, and not just on direct children of an element.

Huddled Masses » Blog Archive » WPF in PowerShell: PowerBoots 0.2. I’ve finally given over trying to improve PowerBoots for this iteration of development, and in between setting up the ScriptingGames.PoshCode site and releasing the PoshCode software on the main PoshCode.org site (it’s coming, I promise), I decided to take a few minutes and release this lates PowerBoots, and it’s a ground-breaking release, if I do say so myself!

Huddled Masses » Blog Archive » WPF in PowerShell: PowerBoots 0.2

PowerShell 1.0 Compatibility There are three huge changes in this release, actually. But the biggest one is that most of the functionality works in the released version of PowerShell 1.0!