The Black Cloud

PowerShell VSCode settings and sample syntax

Welcome to The Black Cloud! This is the first post on the blog as I decided to start from scratch after a long break.

Will keep it short and simple as I just wanted to get the blog up and running.

Over the years I relied on VSCode so much that I got to develop my own settings to fit my style of working.

I am trying to adhere to a specific PowerShell style guide that I developed over the years as there is no real official one, and those VSCode settings should help to enforce it. At least to some degree.

VSCode PowerShell settings

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
 "[powershell]": {
    "files.trimTrailingWhitespace": true,
    "editor.renderWhitespace": "boundary",
    "editor.trimAutoWhitespace": true,
    "editor.wordSeparators": "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?"
  },

  "powershell.powerShellDefaultVersion": "Windows PowerShell (x64)",
  "powershell.promptToUpdatePowerShell": false,

  "powershell.codeFormatting.trimWhitespaceAroundPipe": true,
  "powershell.codeFormatting.openBraceOnSameLine": true,
  "powershell.codeFormatting.whitespaceAfterSeparator": true,
  "powershell.codeFormatting.whitespaceAroundOperator": true,
  "powershell.codeFormatting.whitespaceBeforeOpenParen": true,
  "powershell.codeFormatting.newLineAfterOpenBrace": true,
  "powershell.codeFormatting.addWhitespaceAroundPipe": true,
  "powershell.codeFormatting.autoCorrectAliases": true,
  "powershell.codeFormatting.useCorrectCasing": true,
  "powershell.codeFormatting.newLineAfterCloseBrace": false,
  "powershell.codeFormatting.avoidSemicolonsAsLineTerminators": true,

  "powershell.debugging.createTemporaryIntegratedConsole": true,
  "powershell.integratedConsole.focusConsoleOnExecute": false,

  "powershell.pester.outputVerbosity": "Detailed",
  "powershell.pester.codeLens": false
}

A Quick PowerShell Example

Here is a simple PowerShell snippet to get started show how I like PowerShell formatted:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#region Example code

#region Get system information

$ComputerInfo = Get-ComputerInfo

Write-Host "OS: $($ComputerInfo.OsName)" -ForegroundColor Cyan
Write-Host "Version: $($ComputerInfo.OsVersion)" -ForegroundColor Green

#endregion

#region List running services

$Services = Get-Service | Where-Object -FilterScript { $_.Status -eq 'Running' }

foreach ($Service in $Services) {

    Write-Output -InputObject "Service: $($Service.DisplayName) - Status: $($Service.Status)"

}

#endregion

#endregion

There might be a separate post about the intricacies of PowerShell style, but this should give you an idea 😊

<< Previous Post

|

Next Post >>

#Blog #PowerShell