Files

330 lines
9.7 KiB
PowerShell
Raw Permalink Normal View History

function Initialize-RustEnvironment {
$env:RUSTUP_HOME = "C:\Users\Default\.rustup"
$env:CARGO_HOME = "C:\Users\Default\.cargo"
$env:Path += ";$env:CARGO_HOME\bin"
}
function Get-OSName {
2023-12-04 10:50:53 +01:00
return (Get-CimInstance -ClassName Win32_OperatingSystem).Caption | Get-StringPart -Part 1,2,3
}
function Get-OSVersion {
2020-06-22 01:25:04 -07:00
$OSVersion = (Get-CimInstance -ClassName Win32_OperatingSystem).Version
$OSBuild = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion' UBR).UBR
return "$OSVersion Build $OSBuild"
}
function Build-OSInfoSection {
$osInfoNode = [HeaderNode]::new($(Get-OSName))
$osInfoNode.AddToolVersion("OS Version:", $(Get-OSVersion))
$osInfoNode.AddToolVersion("Image Version:", $env:IMAGE_VERSION)
return $osInfoNode
}
2020-12-14 09:24:20 +03:00
function Get-BashVersion {
bash --% -c 'echo ${BASH_VERSION}'
2020-12-14 09:24:20 +03:00
}
function Get-RustVersion {
2023-12-04 10:50:53 +01:00
rustc --version | Get-StringPart -Part 1
}
function Get-RustupVersion {
2023-12-04 10:50:53 +01:00
cmd /c "rustup --version 2>NUL" | Get-StringPart -Part 1
}
function Get-RustCargoVersion {
2023-12-04 10:50:53 +01:00
cargo --version | Get-StringPart -Part 1
}
function Get-RustdocVersion {
2023-12-04 10:50:53 +01:00
rustdoc --version | Get-StringPart -Part 1
}
function Get-RustfmtVersion {
2023-12-04 10:50:53 +01:00
rustfmt --version | Get-StringPart -Part 1 | Get-StringPart -Part 0 -Delimiter ('-')
}
function Get-RustClippyVersion {
2023-12-04 10:50:53 +01:00
cargo clippy --version | Get-StringPart -Part 1
}
2020-07-07 12:16:42 +03:00
function Get-BindgenVersion {
2023-12-04 10:50:53 +01:00
bindgen --version | Get-StringPart -Part 1
2020-07-07 12:16:42 +03:00
}
function Get-CbindgenVersion {
2023-12-04 10:50:53 +01:00
cbindgen --version | Get-StringPart -Part 1
2020-07-07 12:16:42 +03:00
}
2020-07-09 10:53:31 +03:00
function Get-CargoAuditVersion {
2023-12-04 10:50:53 +01:00
cargo-audit --version | Get-StringPart -Part 1
2020-07-07 12:16:42 +03:00
}
2020-07-09 10:53:31 +03:00
function Get-CargoOutdatedVersion {
2023-12-04 10:50:53 +01:00
cargo outdated --version | Get-StringPart -Part 1
2020-07-07 12:16:42 +03:00
}
2020-07-08 15:25:42 +03:00
function Get-PythonVersion {
2023-12-04 10:50:53 +01:00
python --version | Get-StringPart -Part 1
}
function Get-PowershellCoreVersion {
2023-12-04 10:50:53 +01:00
pwsh --version | Get-StringPart -Part 1
}
function Get-RubyVersion {
2023-12-04 10:50:53 +01:00
ruby --version | Get-StringPart -Part 1
}
function Get-GoVersion {
2023-12-04 10:50:53 +01:00
go version | Get-StringPart -Part 2 | Get-StringPart -Part 1 -Delimiter ('o')
}
2021-08-04 12:19:55 +03:00
function Get-KotlinVersion {
2023-12-04 10:50:53 +01:00
cmd /c "kotlinc -version 2>&1" | Get-StringPart -Part 2
2021-08-04 12:19:55 +03:00
}
function Get-PHPVersion {
2023-12-04 10:50:53 +01:00
php --version | Out-String | Get-StringPart -Part 1
}
function Get-JuliaVersion {
2023-12-04 10:50:53 +01:00
julia --version | Get-StringPart -Part 2
}
2021-09-23 09:52:11 +01:00
function Get-LLVMVersion {
2023-12-04 10:50:53 +01:00
(clang --version) -match "clang" | Get-StringPart -Part 2
2021-09-23 09:52:11 +01:00
}
function Get-PerlVersion {
($(perl --version) | Out-String) -match "\(v(?<version>\d+\.\d+\.\d+)\)" | Out-Null
$perlVersion = $Matches.Version
return $perlVersion
}
function Get-NodeVersion {
2023-12-04 10:50:53 +01:00
node --version | Get-StringPart -Part 0 -Delimiter ('v')
}
function Get-ChocoVersion {
choco --version
}
function Get-VcpkgVersion {
$commitId = git -C "C:\vcpkg" rev-parse --short HEAD
return "(build from commit $commitId)"
}
function Get-NPMVersion {
npm -version
}
function Get-YarnVersion {
yarn -version
}
function Get-RubyGemsVersion {
gem --version
}
function Get-HelmVersion {
($(helm version --short) | Out-String) -match "v(?<version>\d+\.\d+\.\d+)" | Out-Null
$helmVersion = $Matches.Version
return $helmVersion
}
function Get-PipVersion {
2023-12-04 10:50:53 +01:00
(pip --version) -match "pip" | Get-StringPart -Part 1, 4, 5
}
function Get-CondaVersion {
$condaVersion = ((& "$env:CONDA\Scripts\conda.exe" --version) -replace "^conda").Trim()
return "$condaVersion (pre-installed on the image but not added to PATH)"
}
function Get-ComposerVersion {
2023-12-04 10:50:53 +01:00
composer --version | Get-StringPart -Part 2
}
function Get-NugetVersion {
2023-12-04 10:50:53 +01:00
(nuget help) -match "Nuget Version" | Get-StringPart -Part 2
}
function Get-AntVersion {
2023-12-04 10:50:53 +01:00
ant -version | Get-StringPart -Part 3
}
function Get-MavenVersion {
2023-12-04 10:50:53 +01:00
(mvn -version) -match "Apache Maven" | Get-StringPart -Part 2
}
function Get-GradleVersion {
($(gradle -version) | Out-String) -match "Gradle (?<version>\d+\.\d+)" | Out-Null
$gradleVersion = $Matches.Version
return $gradleVersion
}
function Get-SbtVersion {
2023-12-04 10:50:53 +01:00
(sbt -version) -match "sbt script" | Get-StringPart -Part 3
}
function Get-DotnetSdks {
$sdksRawList = dotnet --list-sdks
2023-12-04 10:50:53 +01:00
$sdkVersions = $sdksRawList | Foreach-Object { $_.Split()[0] }
$sdkPath = $sdksRawList[0].Split(' ', 2)[1] -replace '\[|]'
[PSCustomObject]@{
Versions = $sdkVersions
2023-12-04 10:50:53 +01:00
Path = $sdkPath
}
}
2022-01-18 13:31:51 +00:00
function Get-DotnetTools {
2022-01-29 13:00:14 +03:00
$env:Path += ";C:\Users\Default\.dotnet\tools"
2022-01-18 13:31:51 +00:00
$dotnetTools = (Get-ToolsetContent).dotnet.tools
$toolsList = @()
2023-12-04 10:50:53 +01:00
foreach ($dotnetTool in $dotnetTools) {
$version = Invoke-Expression $dotnetTool.getversion
$toolsList += [ToolVersionNode]::new($dotnetTool.name, $version)
2022-01-18 13:31:51 +00:00
}
return $toolsList
}
function Get-DotnetRuntimes {
$runtimesRawList = dotnet --list-runtimes
2023-12-04 10:50:53 +01:00
$runtimesRawList | Group-Object { $_.Split()[0] } | ForEach-Object {
$runtimeName = $_.Name
2023-12-04 10:50:53 +01:00
$runtimeVersions = $_.Group | Foreach-Object { $_.split()[1] }
$runtimePath = $_.Group[0].Split(' ', 3)[2] -replace '\[|]'
[PSCustomObject]@{
2023-12-04 10:50:53 +01:00
"Runtime" = $runtimeName
"Versions" = $runtimeVersions
2023-12-04 10:50:53 +01:00
"Path" = $runtimePath
}
}
}
function Get-DotnetFrameworkVersions {
$path = "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows\*\*\NETFX * Tools"
2023-12-04 10:50:53 +01:00
return Get-ChildItem -Path $path -Directory | ForEach-Object { $_.Name | Get-StringPart -Part 1 }
}
function Get-PowerShellAzureModules {
[Array] $result = @()
$defaultAzureModuleVersion = "2.1.0"
[Array] $azInstalledModules = Get-ChildItem -Path "C:\Modules\az_*" -Directory | ForEach-Object { $_.Name.Split("_")[1] }
if ($azInstalledModules.Count -gt 0) {
$result += [ToolVersionsListNode]::new("Az", $($azInstalledModules), '^\d+\.\d+', "Inline")
}
[Array] $azureInstalledModules = Get-ChildItem -Path "C:\Modules\azure_*" -Directory | ForEach-Object { $_.Name.Split("_")[1] } | ForEach-Object { if ($_ -eq $defaultAzureModuleVersion) { "$($_) (Default)" } else { $_ } }
if ($azureInstalledModules.Count -gt 0) {
$result += [ToolVersionsListNode]::new("Azure", $($azureInstalledModules), '^\d+\.\d+', "Inline")
}
[Array] $azurermInstalledModules = Get-ChildItem -Path "C:\Modules\azurerm_*" -Directory | ForEach-Object { $_.Name.Split("_")[1] } | ForEach-Object { if ($_ -eq $defaultAzureModuleVersion) { "$($_) (Default)" } else { $_ } }
if ($azurermInstalledModules.Count -gt 0) {
$result += [ToolVersionsListNode]::new("AzureRM", $($azurermInstalledModules), '^\d+\.\d+', "Inline")
}
[Array] $azCachedModules = Get-ChildItem -Path "C:\Modules\az_*.zip" -File | ForEach-Object { $_.Name.Split("_")[1] }
if ($azCachedModules.Count -gt 0) {
$result += [ToolVersionsListNode]::new("Az (Cached)", $($azCachedModules), '^\d+\.\d+', "Inline")
}
[Array] $azureCachedModules = Get-ChildItem -Path "C:\Modules\azure_*.zip" -File | ForEach-Object { $_.Name.Split("_")[1] }
if ($azureCachedModules.Count -gt 0) {
$result += [ToolVersionsListNode]::new("Azure (Cached)", $($azureCachedModules), '^\d+\.\d+', "Inline")
}
[Array] $azurermCachedModules = Get-ChildItem -Path "C:\Modules\azurerm_*.zip" -File | ForEach-Object { $_.Name.Split("_")[1] }
if ($azurermCachedModules.Count -gt 0) {
$result += [ToolVersionsListNode]::new("AzureRM (Cached)", $($azurermCachedModules), '^\d+\.\d+', "Inline")
}
return $result
}
function Get-PowerShellModules {
[Array] $result = @()
$result += Get-PowerShellAzureModules
$result += (Get-ToolsetContent).powershellModules.name | Sort-Object | ForEach-Object {
$moduleName = $_
$moduleVersions = Get-Module -Name $moduleName -ListAvailable | Select-Object -ExpandProperty Version | Sort-Object -Unique
return [ToolVersionsListNode]::new($moduleName, $moduleVersions, '^\d+', "Inline")
}
return $result
}
function Get-CachedDockerImages {
return (docker images --digests --format "* {{.Repository}}:{{.Tag}}").Split("*") | Where-Object { $_ }
}
function Get-CachedDockerImagesTableData {
$allImages = docker images --digests --format "*{{.Repository}}:{{.Tag}}|{{.Digest}} |{{.CreatedAt}}"
if (-not $allImages) {
return $null
}
$allImages.Split("*") | Where-Object { $_ } | ForEach-Object {
$parts = $_.Split("|")
[PSCustomObject] @{
"Repository:Tag" = $parts[0]
2023-12-04 10:50:53 +01:00
"Digest" = $parts[1]
"Created" = $parts[2].split(' ')[0]
}
} | Sort-Object -Property "Repository:Tag"
}
2021-01-15 13:42:37 +03:00
function Get-ShellTarget {
2023-12-04 10:50:53 +01:00
return Get-ChildItem C:\shells -File | Select-Object Name, @{n = "Target"; e = {
if ($_.Name -eq "msys2bash.cmd") {
"C:\msys64\usr\bin\bash.exe"
} else {
@($_.Target)[0]
}
2021-01-15 13:42:37 +03:00
}
2023-12-04 10:50:53 +01:00
} | Sort-Object Name
2021-01-15 13:42:37 +03:00
}
function Get-PacmanVersion {
$msys2BinDir = "C:\msys64\usr\bin"
$pacmanPath = Join-Path $msys2BinDir "pacman.exe"
$rawVersion = & $pacmanPath --version
$rawVersion.Split([System.Environment]::NewLine)[1] -match "\d+\.\d+(\.\d+)?" | Out-Null
$pacmanVersion = $matches[0]
return $pacmanVersion
}
function Get-YAMLLintVersion {
2023-12-04 10:50:53 +01:00
yamllint --version | Get-StringPart -Part 1
2020-10-08 16:57:24 +03:00
}
function Get-BizTalkVersion {
$bizTalkReg = Get-ItemProperty "HKLM:\SOFTWARE\WOW6432Node\Microsoft\BizTalk Server\3.0"
return [ToolVersionNode]::new($bizTalkReg.ProductName, $bizTalkReg.ProductVersion)
}
2020-10-08 16:57:24 +03:00
function Get-PipxVersion {
pipx --version
2020-11-05 10:50:57 +03:00
}
function Build-PackageManagementEnvironmentTable {
return @(
[PSCustomObject] @{
"Name" = "VCPKG_INSTALLATION_ROOT"
"Value" = $env:VCPKG_INSTALLATION_ROOT
},
[PSCustomObject] @{
"Name" = "CONDA"
"Value" = $env:CONDA
}
)
}