The code snippet below is something I had to write to simplify some build & deployment. Instead of me having to remember the latest version number to use, this PowerShell snippet lets me store the current version number as a Major.Minor.Patch (for example 1.2.3) one-line text file. The script updates the version number every time it is run.
Some techniques demonstrated:
Write-Host Calculate new version number
$curverfilename= "d:\curver.txt"
$curver = Get-Content $curverfilename | Out-String
Write-Host Current Version $curver
$tokens = $curver.Split(".")
$major = [int]( $tokens[0])
$minor = [int]( $tokens[1])
$patch = [int]( $tokens[2])
$new_patch = $patch + 1
$Version = ([string] $major)+"."+ ([string] $minor ) +"." + ([string]$new_patch)
Write-Host $Version
$Version | Out-File $curverfilename