I work with a lot of PowerShell scripts, it’s the fun part of my job. I do most of my editing using the PowerShell ISE, primarily because it is the default, but also because it has great syntax highlighting, tab completion, and debug support. Additionally, all of my scripts are in source control: sometimes Mercurial, occasionally Git, but mostly Team Foundation Server (TFS).
The way TFS works though, is that all files in your local workspace are marked as read-only until you Check-Out for editing. When working on TFS-managed files in Visual Studio, the check-out is done automatically as soon as you begin typing in the editor. The PowerShell ISE however has no idea about TFS and will let you edit to your heart’s content until you eventually try to save your changes and it fails due to the read-only flag.
But I’ve developed a solution…
I’ve written a PowerShell ISE-specific profile script that performs a few simple things:
- Checks if you have the TFS client installed (eg Team Explorer).
- Registers for ISE events on each open file and any files you open later.
- Upon editing of a file, if it is TFS-managed then checks it out.
The end result is the same TFS workflow experience from within the PowerShell ISE as Visual Studio provides.