Skip to content
An experiment in creating maintainable PowerShell code using classes, unit tests and a task runner.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
SonarQubeDeploy
Tests
.gitignore
LICENSE
README.md
azure-pipelines.yml
build.ps1
psake.ps1
requirements.psd1

README.md

Writing maintainable PowerShell

The goal of this code sample is to research the usage of PowerShell classes, unit tests and a build system.

The following is the original script that I've refactored.

Param(
    [string]$ConnectionString,
    [string]$SqlLogin,
    [string]$SqlPassword
)

$propFile = Get-ChildItem 'sonar.properties' -Recurse
$configContents = Get-Content -Path $propFile.FullName -Raw

$configContents = $configContents -ireplace '#sonar.jdbc.username=', "sonar.jdbc.username=$SqlLogin"
$configContents = $configContents -ireplace '#sonar.jdbc.password=', "sonar.jdbc.password=$SqlPassword"
$configContents = $configContents -ireplace '#sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar;integratedSecurity=true', "#xxx"
$configContents = $configContents -ireplace '#sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar', "sonar.jdbc.url=$ConnectionString"

Set-Content -Path $propFile.FullName -Value $configContents

More details are available in this blog post: http://wouterdekort.com/TODO.

You can’t perform that action at this time.