Skip to content

Instantly share code, notes, and snippets.

View robbratton's full-sized avatar

Robert E. Bratton robbratton

View GitHub Profile
@robbratton
robbratton / .VSCode - ReadME.md
Last active January 30, 2024 19:52
Sample Launch file for Visual Studio Code for PowerShell

Sample launch.json for PowerShell in Visual Studio Code with Testing Scripts

This example includes configurations to start PowerShell in various ways including checking syntax and running tests with code coverage

Requirements

Folders

  • The includes scripts must be in this folder: C:\git\PerfAndMon-Tools\Scripts\Tests
@robbratton
robbratton / .PowerShell - Changing Variables' First Letter to Uppercase
Created January 11, 2024 15:32
Changing PowerShell Variables' First Letter to Uppercase
This example is in Visual Studio Code
Find pattern: \$([a-z])
Set match case to true
Replace pattern: $$\U$1
@robbratton
robbratton / .PowerShell - Regions.md
Last active January 5, 2024 17:58
Using Regions in PowerShell Code

Use Regions in PowerShell

I have verified that this works and the regions can be collapsed and expanded in Visual Studio Code 1.84.2 on 2024-01-05.

Notes:

  • The hyphens and BEGIN/END are not necessary. Only the first #region item needs to have a name.

References:

@robbratton
robbratton / .PowerShell - Aliases.md
Last active January 5, 2024 17:58
PowerShell - Using Aliases for Functions in Modules

Use Aliases in PowerShell Modules

This is useful when you want to maintain backward compatibility when renaming functions in a module so that old code can still use the old name.

In the module file

New-Alias -Name "Get-Policy" -Value "Get-PolicyById"
@robbratton
robbratton / .PowerShell - NLog.md
Last active January 5, 2024 17:59
NLog Config File and Usage Example

Use NLog with a Custom XML Configuration File in PowerShell