[Windows] Use common approach to set machine vars (#8830)

This commit is contained in:
Vasilii Polikarpov
2023-11-17 13:52:52 +01:00
committed by GitHub
parent 045a0de8e2
commit 07e8da79f8
20 changed files with 59 additions and 75 deletions

View File

@@ -3,7 +3,13 @@
## Desc: Configures system environment variables ## Desc: Configures system environment variables
################################################################################ ################################################################################
setx ImageVersion $env:IMAGE_VERSION /m $variables = @{
setx ImageOS $env:IMAGE_OS /m "ImageVersion" = $env:IMAGE_VERSION
setx AGENT_TOOLSDIRECTORY $env:AGENT_TOOLSDIRECTORY /m "ImageOS" = $env:IMAGE_OS
setx ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE $env:ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE /m "AGENT_TOOLSDIRECTORY" = $env:AGENT_TOOLSDIRECTORY
"ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE" = $env:ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE
}
$variables.GetEnumerator() | ForEach-Object {
[Environment]::SetEnvironmentVariable($_.Key, $_.Value, "Machine")
}

View File

@@ -23,7 +23,7 @@ Function Set-DefaultVariables
if (-not ([string]::IsNullOrEmpty($EnvVars.defaultVariable))) if (-not ([string]::IsNullOrEmpty($EnvVars.defaultVariable)))
{ {
setx $toolEnvVars.defaultVariable $ToolVersionPath /M | Out-Null [Environment]::SetEnvironmentVariable($toolEnvVars.defaultVariable, $ToolVersionPath, "Machine")
} }
} }
@@ -48,20 +48,17 @@ $tools = Get-ToolsetContent | Select-Object -ExpandProperty toolcache `
| Where-Object { $toolsToConfigure -contains $_.name } | Where-Object { $toolsToConfigure -contains $_.name }
Write-Host "Configure toolset tools environment..." Write-Host "Configure toolset tools environment..."
foreach ($tool in $tools) foreach ($tool in $tools) {
{
$toolEnvVars = $toolsEnvironmentVariables[$tool.name] $toolEnvVars = $toolsEnvironmentVariables[$tool.name]
if (-not ([string]::IsNullOrEmpty($toolEnvVars.variableTemplate))) if (-not ([string]::IsNullOrEmpty($toolEnvVars.variableTemplate))) {
{ foreach ($version in $tool.versions) {
foreach ($version in $tool.versions)
{
Write-Host "Set $($tool.name) $version environment variable..." Write-Host "Set $($tool.name) $version environment variable..."
$foundVersionArchPath = Get-ToolsetToolFullPath -Name $tool.name -Version $version -Arch $tool.arch $foundVersionArchPath = Get-ToolsetToolFullPath -Name $tool.name -Version $version -Arch $tool.arch
$envName = $toolEnvVars.variableTemplate -f $version.Split(".") $envName = $toolEnvVars.variableTemplate -f $version.Split(".")
setx $envName $foundVersionArchPath /M | Out-Null [Environment]::SetEnvironmentVariable($envName, $foundVersionArchPath, "Machine")
} }
} }

View File

@@ -120,16 +120,16 @@ $ndkDefaultVersion = ($androidNDKs | Where-Object { $_ -match "ndk;$ndkDefaultMa
$ndkRoot = "$sdkRoot\ndk\$ndkDefaultVersion" $ndkRoot = "$sdkRoot\ndk\$ndkDefaultVersion"
# Create env variables # Create env variables
setx ANDROID_HOME $sdkRoot /M [Environment]::SetEnvironmentVariable("ANDROID_HOME", $sdkRoot, "Machine")
setx ANDROID_SDK_ROOT $sdkRoot /M [Environment]::SetEnvironmentVariable("ANDROID_SDK_ROOT", $sdkRoot, "Machine")
# ANDROID_NDK, ANDROID_NDK_HOME, and ANDROID_NDK_ROOT variables should be set as many customer builds depend on them https://github.com/actions/runner-images/issues/5879 # ANDROID_NDK, ANDROID_NDK_HOME, and ANDROID_NDK_ROOT variables should be set as many customer builds depend on them https://github.com/actions/runner-images/issues/5879
setx ANDROID_NDK $ndkRoot /M [Environment]::SetEnvironmentVariable("ANDROID_NDK", $ndkRoot, "Machine")
setx ANDROID_NDK_HOME $ndkRoot /M [Environment]::SetEnvironmentVariable("ANDROID_NDK_HOME", $ndkRoot, "Machine")
setx ANDROID_NDK_ROOT $ndkRoot /M [Environment]::SetEnvironmentVariable("ANDROID_NDK_ROOT", $ndkRoot, "Machine")
$ndkLatestPath = "$sdkRoot\ndk\$ndkLatestVersion" $ndkLatestPath = "$sdkRoot\ndk\$ndkLatestVersion"
if (Test-Path $ndkLatestPath) { if (Test-Path $ndkLatestPath) {
setx ANDROID_NDK_LATEST_HOME $ndkLatestPath /M [Environment]::SetEnvironmentVariable("ANDROID_NDK_LATEST_HOME", $ndkLatestPath, "Machine")
} else { } else {
Write-Host "Latest NDK $ndkLatestVersion is not installed at path $ndkLatestPath" Write-Host "Latest NDK $ndkLatestVersion is not installed at path $ndkLatestPath"
exit 1 exit 1

View File

@@ -78,7 +78,7 @@ Write-Host "Expand Chrome WebDriver archive (without using directory names)..."
Extract-7Zip -Path $ChromeDriverArchPath -DestinationPath $ChromeDriverPath -ExtractMethod "e" Extract-7Zip -Path $ChromeDriverArchPath -DestinationPath $ChromeDriverPath -ExtractMethod "e"
Write-Host "Setting the environment variables..." Write-Host "Setting the environment variables..."
setx ChromeWebDriver "$ChromeDriverPath" /M [Environment]::SetEnvironmentVariable("ChromeWebDriver", $ChromeDriverPath, "Machine")
$regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' $regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\'
$PathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path' $PathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path'

View File

@@ -6,9 +6,9 @@
################################################################################ ################################################################################
# Set environment variables # Set environment variables
Set-SystemVariable -SystemVariable DOTNET_MULTILEVEL_LOOKUP -Value "0" [System.Environment]::SetEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0", "Machine")
Set-SystemVariable -SystemVariable DOTNET_NOLOGO -Value "1" [System.Environment]::SetEnvironmentVariable("DOTNET_NOLOGO", "1", "Machine")
Set-SystemVariable -SystemVariable DOTNET_SKIP_FIRST_TIME_EXPERIENCE -Value "1" [System.Environment]::SetEnvironmentVariable("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1", "Machine")
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor "Tls12" [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor "Tls12"

View File

@@ -38,7 +38,7 @@ $EdgeDriverSignatureThumbprint = ("7C94971221A799907BB45665663BBFD587BAC9F8", "7
Test-FileSignature -FilePath "$EdgeDriverPath\msedgedriver.exe" -ExpectedThumbprint $EdgeDriverSignatureThumbprint Test-FileSignature -FilePath "$EdgeDriverPath\msedgedriver.exe" -ExpectedThumbprint $EdgeDriverSignatureThumbprint
Write-Host "Setting the environment variables..." Write-Host "Setting the environment variables..."
setx EdgeWebDriver "$EdgeDriverPath" /M [Environment]::SetEnvironmentVariable("EdgeWebDriver", $EdgeDriverPath, "Machine")
$regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' $regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\'
$PathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path' $PathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path'

View File

@@ -58,6 +58,6 @@ Test-FileSignature -FilePath "$GeckoDriverPath/geckodriver.exe" -ExpectedThumbpr
Write-Host "Setting the environment variables..." Write-Host "Setting the environment variables..."
Add-MachinePathItem -PathItem $GeckoDriverPath Add-MachinePathItem -PathItem $GeckoDriverPath
setx GeckoWebDriver "$GeckoDriverPath" /M [Environment]::SetEnvironmentVariable("GeckoWebDriver", $GeckoDriverPath, "Machine")
Invoke-PesterTests -TestFile "Browsers" -TestName "Firefox" Invoke-PesterTests -TestFile "Browsers" -TestName "Firefox"

View File

@@ -23,9 +23,9 @@ New-Item -Path "$ghcupPrefix\ghcup" -ItemType 'directory' -ErrorAction SilentlyC
New-Item -Path "$ghcupPrefix\ghcup\bin" -ItemType 'directory' -ErrorAction SilentlyContinue | Out-Null New-Item -Path "$ghcupPrefix\ghcup\bin" -ItemType 'directory' -ErrorAction SilentlyContinue | Out-Null
Start-DownloadWithRetry -Url $ghcupDownloadURL -Name "ghcup.exe" -DownloadPath "$ghcupPrefix\ghcup\bin" Start-DownloadWithRetry -Url $ghcupDownloadURL -Name "ghcup.exe" -DownloadPath "$ghcupPrefix\ghcup\bin"
Set-SystemVariable "GHCUP_INSTALL_BASE_PREFIX" $ghcupPrefix [System.Environment]::SetEnvironmentVariable("GHCUP_INSTALL_BASE_PREFIX", $ghcupPrefix, "Machine")
Set-SystemVariable "GHCUP_MSYS2" $msysPath [System.Environment]::SetEnvironmentVariable("GHCUP_MSYS2", $msysPath, "Machine")
Set-SystemVariable "CABAL_DIR" $cabalDir [System.Environment]::SetEnvironmentVariable("CABAL_DIR", $cabalDir, "Machine")
Add-MachinePathItem "$ghcupPrefix\ghcup\bin" Add-MachinePathItem "$ghcupPrefix\ghcup\bin"
Add-MachinePathItem "$cabalDir\bin" Add-MachinePathItem "$cabalDir\bin"

View File

@@ -33,6 +33,6 @@ Write-Host "Get the IEDriver version..."
(Get-Item "$ieDriverPath\IEDriverServer.exe").VersionInfo.FileVersion | Out-File -FilePath "$ieDriverPath\versioninfo.txt" (Get-Item "$ieDriverPath\IEDriverServer.exe").VersionInfo.FileVersion | Out-File -FilePath "$ieDriverPath\versioninfo.txt"
Write-Host "Setting the IEWebDriver environment variables" Write-Host "Setting the IEWebDriver environment variables"
setx IEWebDriver $ieDriverPath /M [Environment]::SetEnvironmentVariable("IEWebDriver", $ieDriverPath, "Machine")
Invoke-PesterTests -TestFile "Browsers" -TestName "Internet Explorer" Invoke-PesterTests -TestFile "Browsers" -TestName "Internet Explorer"

View File

@@ -20,7 +20,7 @@ function Set-JavaPath {
} }
Write-Host "Set 'JAVA_HOME_${Version}_X64' environmental variable as $javaPath" Write-Host "Set 'JAVA_HOME_${Version}_X64' environmental variable as $javaPath"
setx JAVA_HOME_${Version}_X64 $javaPath /M [Environment]::SetEnvironmentVariable("JAVA_HOME_${Version}_X64", $javaPath, "Machine")
if ($Default) { if ($Default) {
# Clean up any other Java folders from PATH to make sure that they won't conflict with each other # Clean up any other Java folders from PATH to make sure that they won't conflict with each other
@@ -42,7 +42,7 @@ function Set-JavaPath {
Set-MachinePath -NewPath $newPath Set-MachinePath -NewPath $newPath
Write-Host "Set JAVA_HOME environmental variable as $javaPath" Write-Host "Set JAVA_HOME environmental variable as $javaPath"
setx JAVA_HOME $javaPath /M [Environment]::SetEnvironmentVariable("JAVA_HOME", $javaPath, "Machine")
} }
} }
@@ -129,9 +129,9 @@ $maven_opts = '-Xms256m'
$m2_repo = 'C:\ProgramData\m2' $m2_repo = 'C:\ProgramData\m2'
New-Item -Path $m2_repo -ItemType Directory -Force | Out-Null New-Item -Path $m2_repo -ItemType Directory -Force | Out-Null
setx M2 $m2 /M [Environment]::SetEnvironmentVariable("M2", $m2, "Machine")
setx M2_REPO $m2_repo /M [Environment]::SetEnvironmentVariable("M2_REPO", $m2_repo, "Machine")
setx MAVEN_OPTS $maven_opts /M [Environment]::SetEnvironmentVariable("MAVEN_OPTS", $maven_opts, "Machine")
# Download cobertura jars # Download cobertura jars
$uri = 'https://repo1.maven.org/maven2/net/sourceforge/cobertura/cobertura/2.1.1/cobertura-2.1.1-bin.zip' $uri = 'https://repo1.maven.org/maven2/net/sourceforge/cobertura/cobertura/2.1.1/cobertura-2.1.1-bin.zip'
@@ -143,6 +143,6 @@ $fileHash = (Get-FileHash -Path $archivePath -Algorithm SHA256).Hash
Use-ChecksumComparison $fileHash $sha256sum Use-ChecksumComparison $fileHash $sha256sum
Extract-7Zip -Path $archivePath -DestinationPath "C:\" Extract-7Zip -Path $archivePath -DestinationPath "C:\"
setx COBERTURA_HOME $coberturaPath /M [Environment]::SetEnvironmentVariable("COBERTURA_HOME", $coberturaPath, "Machine")
Invoke-PesterTests -TestFile "Java" Invoke-PesterTests -TestFile "Java"

View File

@@ -12,7 +12,7 @@ $InstallerUrl = "https://repo.anaconda.com/miniconda/${InstallerName}"
$ArgumentList = ("/S", "/AddToPath=0", "/RegisterPython=0", "/D=$CondaDestination") $ArgumentList = ("/S", "/AddToPath=0", "/RegisterPython=0", "/D=$CondaDestination")
Install-Binary -Url $InstallerUrl -Name $InstallerName -ArgumentList $ArgumentList Install-Binary -Url $InstallerUrl -Name $InstallerName -ArgumentList $ArgumentList
Set-SystemVariable -SystemVariable "CONDA" -Value $CondaDestination [System.Environment]::SetEnvironmentVariable("CONDA", $CondaDestination, "Machine")
#region Supply chain security #region Supply chain security
$localFileHash = (Get-FileHash -Path (Join-Path ${env:TEMP} $installerName) -Algorithm SHA256).Hash $localFileHash = (Get-FileHash -Path (Join-Path ${env:TEMP} $installerName) -Algorithm SHA256).Hash

View File

@@ -18,7 +18,7 @@ Choco-Install -PackageName nodejs -ArgumentList "--version=$versionToInstall"
Add-MachinePathItem $PrefixPath Add-MachinePathItem $PrefixPath
$env:Path = Get-MachinePath $env:Path = Get-MachinePath
setx npm_config_prefix $PrefixPath /M [Environment]::SetEnvironmentVariable("npm_config_prefix", $PrefixPath, "Machine")
$env:npm_config_prefix = $PrefixPath $env:npm_config_prefix = $PrefixPath
npm config set cache $CachePath --global npm config set cache $CachePath --global

View File

@@ -16,7 +16,7 @@ Choco-Install -PackageName composer -ArgumentList "--ia", "/DEV=$installDir /PHP
((Get-Content -path $installDir\php.ini -Raw) -replace ';extension=curl','extension=curl' -replace ';extension=mbstring','extension=mbstring' -replace ';extension_dir = "ext"','extension_dir = "ext"' -replace ';extension=openssl','extension=openssl') | Set-Content -Path $installDir\php.ini ((Get-Content -path $installDir\php.ini -Raw) -replace ';extension=curl','extension=curl' -replace ';extension=mbstring','extension=mbstring' -replace ';extension_dir = "ext"','extension_dir = "ext"' -replace ';extension=openssl','extension=openssl') | Set-Content -Path $installDir\php.ini
# Set the PHPROOT environment variable. # Set the PHPROOT environment variable.
setx PHPROOT $installDir /M [Environment]::SetEnvironmentVariable("PHPROOT", $installDir, "Machine")
# Invoke Pester Tests # Invoke Pester Tests
Invoke-PesterTests -TestFile "PHP" Invoke-PesterTests -TestFile "PHP"

View File

@@ -10,8 +10,8 @@ $env:PIPX_HOME = "${env:ProgramFiles(x86)}\pipx"
pip install pipx pip install pipx
Add-MachinePathItem "${env:PIPX_BIN_DIR}" Add-MachinePathItem "${env:PIPX_BIN_DIR}"
Set-SystemVariable -SystemVariable PIPX_BIN_DIR -Value $env:PIPX_BIN_DIR [System.Environment]::SetEnvironmentVariable("PIPX_BIN_DIR", $env:PIPX_BIN_DIR, "Machine")
Set-SystemVariable -SystemVariable PIPX_HOME -Value $env:PIPX_HOME [System.Environment]::SetEnvironmentVariable("PIPX_HOME", $env:PIPX_HOME, "Machine")
Invoke-PesterTests -TestFile "Tools" -TestName "Pipx" Invoke-PesterTests -TestFile "Tools" -TestName "Pipx"

View File

@@ -3,22 +3,22 @@ $pgUser = "postgres"
$pgPwd = "root" $pgPwd = "root"
# Prepare environment variable for validation # Prepare environment variable for validation
Set-SystemVariable -SystemVariable PGUSER -Value $pgUser [System.Environment]::SetEnvironmentVariable("PGUSER", $pgUser, "Machine")
Set-SystemVariable -SystemVariable PGPASSWORD -Value $pgPwd [System.Environment]::SetEnvironmentVariable("PGPASSWORD", $pgPwd, "Machine")
# Define latest available version to install based on version specified in the toolset # Define latest available version to install based on version specified in the toolset
$toolsetVersion = (Get-ToolsetContent).postgresql.version $toolsetVersion = (Get-ToolsetContent).postgresql.version
$getPostgreReleases = Invoke-WebRequest -Uri "https://git.postgresql.org/gitweb/?p=postgresql.git;a=tags" -UseBasicParsing $getPostgreReleases = Invoke-WebRequest -Uri "https://git.postgresql.org/gitweb/?p=postgresql.git;a=tags" -UseBasicParsing
# Getting all links matched to the pattern (e.g.a=log;h=refs/tags/REL_14) # Getting all links matched to the pattern (e.g.a=log;h=refs/tags/REL_14)
$TargetReleases = $getPostgreReleases.Links.href | Where-Object {$_ -match "a=log;h=refs/tags/REL_$toolsetVersion"} $TargetReleases = $getPostgreReleases.Links.href | Where-Object { $_ -match "a=log;h=refs/tags/REL_$toolsetVersion" }
[Int32]$OutNumber = $null [Int32]$OutNumber = $null
$MinorVersions = @() $MinorVersions = @()
foreach ($release in $TargetReleases) { foreach ($release in $TargetReleases) {
$version = $release.split('/')[-1] $version = $release.split('/')[-1]
# Checking if the latest symbol of the release version is actually a number. If yes, add to $MinorVersions array # Checking if the latest symbol of the release version is actually a number. If yes, add to $MinorVersions array
if ([Int32]::TryParse($($version.Split('_')[-1]),[ref]$OutNumber)){ if ([Int32]::TryParse($($version.Split('_')[-1]), [ref]$OutNumber)) {
$MinorVersions += $OutNumber $MinorVersions += $OutNumber
} }
} }
# Sorting and getting the last one # Sorting and getting the last one
$TargetMinorVersions = ($MinorVersions | Sort-Object)[-1] $TargetMinorVersions = ($MinorVersions | Sort-Object)[-1]
@@ -47,7 +47,7 @@ do {
# Return the previous value of ErrorAction and invoke Install-Binary function # Return the previous value of ErrorAction and invoke Install-Binary function
$ErrorActionPreference = $ErrorActionOldValue $ErrorActionPreference = $ErrorActionOldValue
$InstallerName = $InstallerUrl.Split('/')[-1] $InstallerName = $InstallerUrl.Split('/')[-1]
$ArgumentList = ("--install_runtimes 0","--superpassword root","--enable_acledit 1","--unattendedmodeui none","--mode unattended") $ArgumentList = ("--install_runtimes 0", "--superpassword root", "--enable_acledit 1", "--unattendedmodeui none", "--mode unattended")
Install-Binary -Url $InstallerUrl -Name $InstallerName -ArgumentList $ArgumentList -ExpectedSignature (Get-ToolsetContent).postgresql.signature Install-Binary -Url $InstallerUrl -Name $InstallerName -ArgumentList $ArgumentList -ExpectedSignature (Get-ToolsetContent).postgresql.signature
# Get Path to pg_ctl.exe # Get Path to pg_ctl.exe
@@ -63,16 +63,15 @@ $pgReadyPath = Join-Path $pgBin "pg_isready.exe"
$pgReady = Start-Process -FilePath $pgReadyPath -Wait -PassThru $pgReady = Start-Process -FilePath $pgReadyPath -Wait -PassThru
$exitCode = $pgReady.ExitCode $exitCode = $pgReady.ExitCode
if ($exitCode -ne 0) if ($exitCode -ne 0) {
{
Write-Host -Object "PostgreSQL is not ready. Exitcode: $exitCode" Write-Host -Object "PostgreSQL is not ready. Exitcode: $exitCode"
exit $exitCode exit $exitCode
} }
# Added PostgreSQL environment variable # Added PostgreSQL environment variable
Set-SystemVariable -SystemVariable PGBIN -Value $pgBin [System.Environment]::SetEnvironmentVariable("PGBIN", $pgBin, "Machine")
Set-SystemVariable -SystemVariable PGROOT -Value $pgRoot [System.Environment]::SetEnvironmentVariable("PGROOT", $pgRoot, "Machine")
Set-SystemVariable -SystemVariable PGDATA -Value $pgData [System.Environment]::SetEnvironmentVariable("PGDATA", $pgData, "Machine")
# Stop and disable PostgreSQL service # Stop and disable PostgreSQL service
$pgService = Get-Service -Name postgresql* $pgService = Get-Service -Name postgresql*

View File

@@ -27,6 +27,6 @@ New-Item -Path $seleniumDirectory -Name "$seleniumBinaryName-$seleniumFullVersio
# Add SELENIUM_JAR_PATH environment variable # Add SELENIUM_JAR_PATH environment variable
$seleniumBinPath = Join-Path $seleniumDirectory $seleniumFileName $seleniumBinPath = Join-Path $seleniumDirectory $seleniumFileName
setx "SELENIUM_JAR_PATH" "$($seleniumBinPath)" /M [Environment]::SetEnvironmentVariable("SELENIUM_JAR_PATH", $seleniumBinPath, "Machine")
Invoke-PesterTests -TestFile "Browsers" -TestName "Selenium" Invoke-PesterTests -TestFile "Browsers" -TestName "Selenium"

View File

@@ -16,6 +16,6 @@ Invoke-Expression "$InstallDir\$VcpkgExecPath integrate install"
# Add vcpkg to system environment # Add vcpkg to system environment
Add-MachinePathItem $InstallDir Add-MachinePathItem $InstallDir
$env:Path = Get-MachinePath $env:Path = Get-MachinePath
setx VCPKG_INSTALLATION_ROOT $InstallDir /M [Environment]::SetEnvironmentVariable("VCPKG_INSTALLATION_ROOT", $InstallDir, "Machine")
Invoke-PesterTests -TestFile "Tools" -TestName "Vcpkg" Invoke-PesterTests -TestFile "Tools" -TestName "Vcpkg"

View File

@@ -19,7 +19,6 @@ Export-ModuleMember -Function @(
'Add-DefaultItem' 'Add-DefaultItem'
'Get-SystemVariable' 'Get-SystemVariable'
'Get-DefaultVariable' 'Get-DefaultVariable'
'Set-SystemVariable'
'Set-DefaultVariable' 'Set-DefaultVariable'
'Install-Binary' 'Install-Binary'
'Install-VisualStudio' 'Install-VisualStudio'

View File

@@ -54,16 +54,6 @@ function Get-DefaultVariable {
[System.GC]::Collect() [System.GC]::Collect()
} }
function Set-SystemVariable {
param(
[string]$SystemVariable,
[string]$Value
)
[System.Environment]::SetEnvironmentVariable($SystemVariable, $Value, "Machine")
Get-SystemVariable $SystemVariable
}
function Set-DefaultVariable { function Set-DefaultVariable {
param( param(
[string]$DefaultVariable, [string]$DefaultVariable,
@@ -93,7 +83,7 @@ function Set-MachinePath {
[string]$NewPath [string]$NewPath
) )
Set-SystemVariable PATH $NewPath [System.Environment]::SetEnvironmentVariable("PATH", $NewPath, "Machine")
} }
function Set-DefaultPath { function Set-DefaultPath {

View File

@@ -25,10 +25,3 @@ Describe "Add-MachinePathItem Tests"{
Add-MachinePathItem -PathItem 'C:\baz' | Should Be 'C:\baz;C:\foo;C:\bar' Add-MachinePathItem -PathItem 'C:\baz' | Should Be 'C:\baz;C:\foo;C:\bar'
} }
} }
Describe 'Set-SystemVariable Tests' {
Mock Set-ItemProperty {return}
It 'Set-SystemVariable should return new path' {
Set-SystemVariable -SystemVariable "NewPathVar" -Value "C:\baz" | Should Be "C:\baz"
}
}