Posts

Out-GridView to present and demo results more easily.

Image
Background:  I recently had the opportunity to see a presentation involving FabTools (PowerShell Module for Fabric) .  The audience was PowerShell-light, and it was the end of long week, so even a small interruption in the flow had potential to lose traction. So it made me think about a small way that live demos can be streamlined for both presenters and viewers. Using | Out-GridView for presenting, demonstrating, and sharing. When we're sharing the results of our actions in PowerShell we have the advantage of knowing what we're looking for and what we're looking at. Our audience however may be deep in unfamiliar territory. Out-GridView can be a visual communication tool that helps them to catch up. Because Out-GridView is an output tool and not a scripting tool it is easily forgotten (or unknown) to people who are very competent in PowerShell. Generally I use this cmdlet when I'm sharing information with others (either looking at the same screen, or doing a quick paste...

Default Browser - set url association with PowerShell

 Something that is helpful to know for complicated environments. Background: We have a legacy software that is in the process of being rewritten as a Blazor application, as we begin integrating these things together one need is to make sure that invoked urls do not open in Internet Explorer.  Policy and OU based controls are not available within the timeline we're looking at. However we have an advantage in the fact that we're already using a .ps1 script that prepares some environment needs before  the software executes. Other alternatives: A popular recommendation for handling this is to work within the DefaultAssociationsConfiguration structure. This is a good option, and is well covered in articles like this:  set-default-browser-to-microsoft-edge-using-powershell/ Why this solution: This solution fits a need where anything that may cause IE to be reset as default is handled promptly without requiring a logoff or restart to take effect.  Components: Registry ...

Blogger and Code Highlighting

Image
Just a few quick notes on achieving nice code highlighting for sharing. My preferred method is to use Visual Studio Code to achieve highlighting.  If you have a language extension installed, then VS Code will copy with rich HTML formatting that looks sharp and consistent. But doesn't quite match the original.  Here's a line of SQL: SELECT CONVERT ( DATETIME2 ( 3 ), GETDATE ()) ; And here's how it looks in my VS Code I do wish that the layered bracket highlighting would transfer over, but honestly that's a very small difference, and I give VS Code high marks for quality of export. Not long ago PowerShell code highlighting or SQL code highlighting was not this easy to achieve; since the most readily available editors didn't provide it natively. My secondary method. Code highlighting is from  http://hilite.me/    Style: Monokai  For PowerShell code I made a manual correction, to adjust the hard to read formatting applied to double quotes, semi-colons, e...

Powershell OpenFileDialog

This is my preferred version of a function for calling a Windows GUI OpenFileDialog. Adding a few GUI elements can be the difference between a script for your own use, and a sharable tool that people with less experience (or fear of CLI) can use. This function invokes the standard .NET System.windows.forms tools within a PowerShell context. Function Get-FilesFromDialog () {     Param (     [ Parameter ( Mandatory =$ False )][ String []]$ myInitialDirectory = $ env:USERPROFILE ,     [ Parameter ( Mandatory =$ False )][ String []]$ myTitle = "Open File" ,     [ Parameter ( Mandatory =$ False , )][ String []]$ myFilterString = ""  )  [ System.Reflection.Assembly ]::LoadWithPartialName( “System.windows.forms” ) | Out-Null  $ OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog  $ OpenFileDialog .initialDirectory = $ myInitialDirectory  $ OpenFileDialog .filter = " $ myFilterString " + “All files (*.*)...

Tome files - digital equivalent of the trusty notebook

Image
 I've been keeping Tomes for a long time now. They are the trusty text files representing my collective experience; the tricks, techniques, and syntaxes for various systems and languages. The name came from a bit of advice in an old article in 2600. Something along the lines of "We may be reaching the point where a notebook and pen can no longer keep up, but technology now allows us to have an always available text file equivalent. Digital Tomes." The name stuck. It calls to mind old handwritten leather bound volumes belonging to scholars, 18th century scientists, philosophers, and other madman. It evokes a bit of science, and fiction, and RPG.  I keep mine as simple text files, but named with a .tome extension which makes them easy to spot.  I tend to have my most important ones constantly open as tabs in Notepad++ and reference them and update them frequently. There's a bit of a style convention to them using dashes to represent nesting and idea breaks. There are se...

LINQ within a foreach()

  An example of how LINQ where clauses save steps. The where can occur right within the declaration of the foreach LAMBDA syntax: foreach (var person in people.Where(n => n.sex == "male")) { ... } Query Syntax: foreach (var person in from person in people where person.sex == "male" select person) { ... } Both syntaxes compile to the same code (Credit to  @YuvalItzchakov   https://stackoverflow.com/a/25412168 )

Almost Boring - 1st week reflections

Image
  I hit my goal of posting 6 times in the first week. So far, I like it. Which of course will only be part of what determines whether or not I stick with it. The blogger platform is easy to use, seems like a decent place to capture ideas I want to remember, and should be good for when I actually have things that I want to share.  The conversational style is a nice way to engage in reflection, bringing together separate threads and trying to turn them into a coherent idea. And ultimately, it feels good to write again. That's something I haven't made time for in a long while. It's not the feeling that I used to get; but in the frustrated and exhausted wreckage of adulthood, with the ashes of inspiration long grown cold... it's as much as I can expect.