Let's say I have this:
[System.Version]::new(1, 2, 3, 4)
How can I convert it into "3.4"? I'm interested in piping it if possible to avoid having to create an intermediary variable.
You could also consider creating a Function for this that worked via Pipeline input:
Function ConvertTo-BuildRevision {
Param(
[Parameter(ValueFromPipeline)]
[system.version]
$Version
)
Process {
Return "$($Version.Build).$($Version.Revision)"
}
}
[System.Version]::new(1, 2, 3, 4) | ConvertTo-BuildRevision
This is obviously a lot more lines of code, but if you were performing this kind of conversion multiple times in your code would look a lot cleaner.
A regex-based solution with the -replace operator:
PS> [System.Version]::new(1, 2, 3, 4) -replace '^(.+?\.){2}'
3.4