Get the Owner of a Process in PowerShell – P/Invoke and Ref/Out Parameters

An often asked question in the Managed Code world is “How do I get the owner of a process?” The same question is starting to come up around PowerShell, and the answer to both is: The .Net Framework does not yet support this API, so the solution is to write the P/Invoke calls into the Win32 API yourself. This gets a little more complicated with PowerShell, though, since we abstract the .

Set-Location, and [Environment]::CurrentDirectory

One question that comes up frequently is, “Why does PowerShell not change its [System.Environment]::CurrentDirectory as I navigate around the shell?” One of the difficult aspects of this comes from the fact that PowerShell supports multiple pipelines of execution. Although it’s not directly exposed yet, users will soon be able to suspend jobs to the background, and other concurrent tasks. The current directory affects the entire process, so if we change the directory as you navigate around the shell, you risk corrupting the environment of jobs you have running in the background.

PowerShell Solves a Mystery

One of Raymond Chen’s readers recently noticed that Google purchased AdWords for Raymond’s name. The destination of the sponsored link? http://www.google.com/jobs :) This came up on our internal bloggers alias, so people started poking around to see what other bloggers / blog readership had outstanding “job offers.” Not being one for repetitive, manual computer labour, I let PowerShell definitively answer the question. In a temporary Outlook message, I expanded the alias so that it listed the names of all members.

How Do I Search the Registry for a Value in PowerShell?

The question came up recently in an internal discussion list, “How do I search the Registry for a value in PowerShell?” In the FileSystem, we have the select-string cmdlet to do the hard work for you. We don’t have the equivalent yet for other stores, so unfortunately the answer is to write ‘grep’ from scratch. It’s manageable, though. The key here is to think of registry key values like you would think of content in a file:

“Simple Where” as a Where-Object Shortcut

The Where-Object cmdlet is incredibly powerful, in that it allows you to filter your output based on arbitrary criteria. For extremely simple filters (such as filtering based only on a comparison to a single property,) though the syntax can get a little ungainly: get-process | where { $_.Handles -gt 1000 } For this type of situation, it is easy to write a function to offload all of the syntax to the function itself:

Current Working Directory with PowerShell and .Net Calls

A question that occasionally comes up is, “Why doesn’t PowerShell change the [Environment]::CurrentDirectory while I navigate around the shell?” This is always in the context of using a relative file path while working with the .Net framework. One of the difficult aspects of this comes from the fact that PowerShell supports multiple pipelines of execution. Although it’s not directly exposed yet, users will soon be able to suspend jobs to the background, and other concurrent tasks.

Note Trainer - Musical Staff Trainer

I wrote Note Trainer to help me learn guitar. It shows a random note on the treble cleff staff, delays a bit, then plays the actual note. You play the note as soon as you see it, then decide for yourself if you played the right one :)

Precision Computing Turns One

It was a year ago now that Precision Computing, in its current form, opened its doors. I’ve been writing something blog-like for longer, but it previously involved updating the HTML by hand :) It’s been an interesting year – one in which we’ve seen the PowerShell community blossom from a group of passionate BetaPlace users, to a much larger and more diverse community. We’ve played with a handful of new releases, experienced a long-awaited name change, and perhaps most importantly – learned about PowerShell’s official release plans.

Cafe Artigiano in Vancouver

On a recent trip to Vancouver, I accidentally stumbled into a cafe called Caffe Artigiano right downtown (on Hornsby street,) and was extremely impressed. The walls are decorated with pictures of gorgeous Latte art, and the drinks are stellar. It turns out that the place is the home of the Canadian Barista Champion for three years running! And with drinks like this? It makes me want to go back to working for a coffee shop :)

SecureStrings in PowerShell

When you use any string in the CLR, it retains that string so that it can efficiently reuse it later. Unlike most .Net data, unused strings persist even through garbage collection cycles. While this data is in memory, there is always the chance that it could get captured in a crash dump, or swapped to disk in a paging operation. Because some data (such as passwords, and other confidential information) may be sensitive, the .