2020-03-25 02:08:37 +08:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-04-03 01:47:29 +08:00
|
|
|
# Licensed under the MIT License.
|
|
|
|
|
2020-05-23 21:24:53 +08:00
|
|
|
Describe -Name "Windows MSI" -Fixture {
|
|
|
|
BeforeAll {
|
2021-07-15 06:41:56 +08:00
|
|
|
Set-StrictMode -Off
|
2020-05-23 21:24:53 +08:00
|
|
|
function Test-Elevated {
|
|
|
|
[CmdletBinding()]
|
|
|
|
[OutputType([bool])]
|
|
|
|
Param()
|
2018-04-03 01:47:29 +08:00
|
|
|
|
2020-05-23 21:24:53 +08:00
|
|
|
# if the current Powershell session was called with administrator privileges,
|
|
|
|
# the Administrator Group's well-known SID will show up in the Groups for the current identity.
|
|
|
|
# Note that the SID won't show up unless the process is elevated.
|
|
|
|
return (([Security.Principal.WindowsIdentity]::GetCurrent()).Groups -contains "S-1-5-32-544")
|
|
|
|
}
|
2018-04-03 01:47:29 +08:00
|
|
|
|
2021-07-15 06:41:56 +08:00
|
|
|
function Test-IsMuEnabled {
|
|
|
|
$sm = (New-Object -ComObject Microsoft.Update.ServiceManager)
|
|
|
|
$mu = $sm.Services | Where-Object { $_.ServiceId -eq '7971f918-a847-4430-9279-4a52d1efe18d' }
|
|
|
|
if ($mu) {
|
|
|
|
return $true
|
|
|
|
}
|
|
|
|
return $false
|
|
|
|
}
|
|
|
|
|
|
|
|
function Invoke-TestAndUploadLogOnFailure {
|
|
|
|
param (
|
|
|
|
[scriptblock] $Test
|
|
|
|
)
|
|
|
|
|
|
|
|
try {
|
|
|
|
& $Test
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
Send-VstsLogFile -Path $msiLog
|
|
|
|
throw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function Get-UseMU {
|
2021-12-07 05:18:44 +08:00
|
|
|
$useMu = $null
|
2021-07-15 06:41:56 +08:00
|
|
|
$key = 'HKLM:\SOFTWARE\Microsoft\PowerShellCore\'
|
|
|
|
if ($runtime -like '*x86*') {
|
|
|
|
$key = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\PowerShellCore\'
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$useMu = Get-ItemPropertyValue -Path $key -Name UseMU -ErrorAction SilentlyContinue
|
|
|
|
} catch {}
|
|
|
|
|
2021-12-07 05:18:44 +08:00
|
|
|
if (!$useMu) {
|
|
|
|
$useMu = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return $useMu
|
|
|
|
}
|
|
|
|
|
|
|
|
function Set-UseMU {
|
|
|
|
param(
|
|
|
|
[int]
|
|
|
|
$Value
|
|
|
|
)
|
|
|
|
$key = 'HKLM:\SOFTWARE\Microsoft\PowerShellCore\'
|
|
|
|
if ($runtime -like '*x86*') {
|
|
|
|
$key = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\PowerShellCore\'
|
|
|
|
}
|
|
|
|
|
|
|
|
Set-ItemProperty -Path $key -Name UseMU -Value $Value -Type DWord
|
|
|
|
|
2021-07-15 06:41:56 +08:00
|
|
|
return $useMu
|
|
|
|
}
|
|
|
|
|
2020-05-23 21:24:53 +08:00
|
|
|
function Invoke-Msiexec {
|
|
|
|
param(
|
|
|
|
[Parameter(ParameterSetName = 'Install', Mandatory)]
|
|
|
|
[Switch]$Install,
|
2018-04-03 01:47:29 +08:00
|
|
|
|
2020-05-23 21:24:53 +08:00
|
|
|
[Parameter(ParameterSetName = 'Uninstall', Mandatory)]
|
|
|
|
[Switch]$Uninstall,
|
2018-04-03 01:47:29 +08:00
|
|
|
|
2020-05-23 21:24:53 +08:00
|
|
|
[Parameter(Mandatory)]
|
|
|
|
[ValidateScript({Test-Path -Path $_})]
|
|
|
|
[String]$MsiPath,
|
2018-04-03 01:47:29 +08:00
|
|
|
|
2020-05-23 21:24:53 +08:00
|
|
|
[Parameter(ParameterSetName = 'Install')]
|
|
|
|
[HashTable] $Properties
|
2018-04-03 01:47:29 +08:00
|
|
|
|
2020-05-23 21:24:53 +08:00
|
|
|
)
|
|
|
|
$action = "$($PSCmdlet.ParameterSetName)ing"
|
|
|
|
if ($Install.IsPresent) {
|
|
|
|
$switch = '/I'
|
|
|
|
} else {
|
|
|
|
$switch = '/x'
|
|
|
|
}
|
2018-04-03 01:47:29 +08:00
|
|
|
|
2020-05-23 21:24:53 +08:00
|
|
|
$additionalOptions = @()
|
|
|
|
if ($Properties) {
|
|
|
|
foreach ($key in $Properties.Keys) {
|
|
|
|
$additionalOptions += "$key=$($Properties.$key)"
|
|
|
|
}
|
|
|
|
}
|
2018-04-03 01:47:29 +08:00
|
|
|
|
2020-05-23 21:24:53 +08:00
|
|
|
$argumentList = "$switch $MsiPath /quiet /l*vx $msiLog $additionalOptions"
|
2021-07-15 06:41:56 +08:00
|
|
|
Write-Verbose -Message "running msiexec $argumentList"
|
2020-05-23 21:24:53 +08:00
|
|
|
$msiExecProcess = Start-Process msiexec.exe -Wait -ArgumentList $argumentList -NoNewWindow -PassThru
|
|
|
|
if ($msiExecProcess.ExitCode -ne 0) {
|
|
|
|
$exitCode = $msiExecProcess.ExitCode
|
|
|
|
throw "$action MSI failed and returned error code $exitCode."
|
|
|
|
}
|
|
|
|
}
|
2018-04-03 01:47:29 +08:00
|
|
|
|
|
|
|
$msiX64Path = $env:PsMsiX64Path
|
2021-02-09 05:25:14 +08:00
|
|
|
$channel = $env:PSMsiChannel
|
|
|
|
$runtime = $env:PSMsiRuntime
|
2021-07-15 06:41:56 +08:00
|
|
|
$muEnabled = Test-IsMuEnabled
|
2018-04-03 01:47:29 +08:00
|
|
|
|
2024-05-08 05:45:50 +08:00
|
|
|
if ($runtime -like '*x86*') {
|
|
|
|
$propertiesRegKeyParent = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\PowerShellCore"
|
|
|
|
} else {
|
|
|
|
$propertiesRegKeyParent = "HKLM:\SOFTWARE\Microsoft\PowerShellCore"
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($channel -eq "preview") {
|
|
|
|
$propertiesRegKeyName = "PreviewInstallerProperties"
|
|
|
|
} else {
|
|
|
|
$propertiesRegKeyName = "InstallerProperties"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Rename the registry key that contains the saved installer
|
|
|
|
# properties so that the tests don't overwrite them.
|
|
|
|
$propertiesRegKeyPath = Join-Path -Path $propertiesRegKeyParent -ChildPath $propertiesRegKeyName
|
|
|
|
$propertiesBackupRegKeyName = "BackupInstallerProperties"
|
|
|
|
$propertiesBackupRegKeyPath = Join-Path -Path $propertiesRegKeyParent -ChildPath $propertiesBackupRegKeyName
|
|
|
|
if (Test-Path -Path $propertiesRegKeyPath) {
|
|
|
|
Rename-Item -Path $propertiesRegKeyPath -NewName $propertiesBackupRegKeyName
|
|
|
|
}
|
|
|
|
|
2019-05-11 06:34:27 +08:00
|
|
|
# Get any existing powershell in the path
|
2018-04-03 01:47:29 +08:00
|
|
|
$beforePath = @(([System.Environment]::GetEnvironmentVariable('PATH', 'MACHINE')) -split ';' |
|
|
|
|
Where-Object {$_ -like '*files\powershell*'})
|
|
|
|
|
|
|
|
$msiLog = Join-Path -Path $TestDrive -ChildPath 'msilog.txt'
|
|
|
|
|
|
|
|
foreach ($pathPart in $beforePath) {
|
|
|
|
Write-Warning "Found existing PowerShell path: $pathPart"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(Test-Elevated)) {
|
|
|
|
Write-Warning "Tests must be elevated"
|
|
|
|
}
|
|
|
|
$uploadedLog = $false
|
|
|
|
}
|
2021-07-15 06:41:56 +08:00
|
|
|
|
|
|
|
AfterAll {
|
|
|
|
Set-StrictMode -Version 3.0
|
2024-05-08 05:45:50 +08:00
|
|
|
|
|
|
|
# Restore the original saved installer properties registry key.
|
|
|
|
Remove-Item -Path $propertiesRegKeyPath -ErrorAction SilentlyContinue
|
|
|
|
if (Test-Path -Path $propertiesBackupRegKeyPath) {
|
|
|
|
Rename-Item -Path $propertiesBackupRegKeyPath -NewName $propertiesRegKeyName
|
|
|
|
}
|
2021-07-15 06:41:56 +08:00
|
|
|
}
|
|
|
|
|
2018-04-03 01:47:29 +08:00
|
|
|
BeforeEach {
|
2020-01-14 03:19:39 +08:00
|
|
|
$error.Clear()
|
2024-05-08 05:45:50 +08:00
|
|
|
Remove-Item -Path $propertiesRegKeyPath -ErrorAction SilentlyContinue
|
2018-04-03 01:47:29 +08:00
|
|
|
}
|
|
|
|
|
2020-06-30 05:13:10 +08:00
|
|
|
Context "Upgrade code" {
|
|
|
|
BeforeAll {
|
2021-02-09 05:25:14 +08:00
|
|
|
Write-Verbose "cr-$channel-$runtime" -Verbose
|
2021-06-16 04:44:08 +08:00
|
|
|
$pwshPath = Join-Path $env:ProgramFiles -ChildPath "PowerShell"
|
|
|
|
$pwshx86Path = Join-Path ${env:ProgramFiles(x86)} -ChildPath "PowerShell"
|
2023-05-10 13:36:34 +08:00
|
|
|
$regKeyPath = "HKLM:\SOFTWARE\Microsoft\PowerShellCore\InstalledVersions"
|
2021-06-16 04:44:08 +08:00
|
|
|
|
2022-10-19 07:48:07 +08:00
|
|
|
switch ("$channel-$runtime") {
|
|
|
|
"preview-win7-x64" {
|
2021-06-16 04:44:08 +08:00
|
|
|
$versionPath = Join-Path -Path $pwshPath -ChildPath '7-preview'
|
|
|
|
$revisionRange = 0, 99
|
2021-02-09 05:25:14 +08:00
|
|
|
$msiUpgradeCode = '39243d76-adaf-42b1-94fb-16ecf83237c8'
|
2023-05-10 13:36:34 +08:00
|
|
|
$regKeyPath = Join-Path $regKeyPath -ChildPath $msiUpgradeCode
|
2021-02-09 05:25:14 +08:00
|
|
|
}
|
2022-10-19 07:48:07 +08:00
|
|
|
"stable-win7-x64" {
|
2021-06-16 04:44:08 +08:00
|
|
|
$versionPath = Join-Path -Path $pwshPath -ChildPath '7'
|
|
|
|
$revisionRange = 500, 500
|
2021-02-09 05:25:14 +08:00
|
|
|
$msiUpgradeCode = '31ab5147-9a97-4452-8443-d9709f0516e1'
|
2023-05-10 13:36:34 +08:00
|
|
|
$regKeyPath = Join-Path $regKeyPath -ChildPath $msiUpgradeCode
|
2021-02-09 05:25:14 +08:00
|
|
|
}
|
2022-10-19 07:48:07 +08:00
|
|
|
"preview-win7-x86" {
|
2021-06-16 04:44:08 +08:00
|
|
|
$versionPath = Join-Path -Path $pwshx86Path -ChildPath '7-preview'
|
|
|
|
$revisionRange = 0, 99
|
2021-02-09 05:25:14 +08:00
|
|
|
$msiUpgradeCode = '86abcfbd-1ccc-4a88-b8b2-0facfde29094'
|
2023-05-10 13:36:34 +08:00
|
|
|
$regKeyPath = Join-Path $regKeyPath -ChildPath $msiUpgradeCode
|
2021-02-09 05:25:14 +08:00
|
|
|
}
|
2022-10-19 07:48:07 +08:00
|
|
|
"stable-win7-x86" {
|
2021-06-16 04:44:08 +08:00
|
|
|
$versionPath = Join-Path -Path $pwshx86Path -ChildPath '7'
|
|
|
|
$revisionRange = 500, 500
|
2021-02-09 05:25:14 +08:00
|
|
|
$msiUpgradeCode = '1d00683b-0f84-4db8-a64f-2f98ad42fe06'
|
2023-05-10 13:36:34 +08:00
|
|
|
$regKeyPath = Join-Path $regKeyPath -ChildPath $msiUpgradeCode
|
2021-02-09 05:25:14 +08:00
|
|
|
}
|
|
|
|
default {
|
|
|
|
throw "'$_' not a valid channel runtime combination"
|
|
|
|
}
|
|
|
|
}
|
2020-06-30 05:13:10 +08:00
|
|
|
}
|
|
|
|
|
2021-02-09 05:25:14 +08:00
|
|
|
It "$Channel MSI should not be installed before test" -Skip:(!(Test-Elevated)) {
|
|
|
|
$result = @(Get-CimInstance -Query "SELECT Value FROM Win32_Property WHERE Property='UpgradeCode' and Value = '{$msiUpgradeCode}'")
|
2021-02-20 07:39:35 +08:00
|
|
|
$result.Count | Should -Be 0 -Because "Query should return nothing if $channel $runtime is not installed"
|
2020-06-30 05:13:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
It "MSI should install without error" -Skip:(!(Test-Elevated)) {
|
|
|
|
{
|
|
|
|
Invoke-MsiExec -Install -MsiPath $msiX64Path -Properties @{ADD_PATH = 1}
|
|
|
|
} | Should -Not -Throw
|
|
|
|
}
|
|
|
|
|
|
|
|
It "Upgrade code should be correct" -Skip:(!(Test-Elevated)) {
|
2021-02-09 05:25:14 +08:00
|
|
|
$result = @(Get-CimInstance -Query "SELECT Value FROM Win32_Property WHERE Property='UpgradeCode' and Value = '{$msiUpgradeCode}'")
|
2021-02-20 07:39:35 +08:00
|
|
|
$result.Count | Should -Be 1 -Because "Query should return 1 result if Upgrade code is for $runtime $channel"
|
2020-06-30 05:13:10 +08:00
|
|
|
}
|
|
|
|
|
2021-06-16 04:44:08 +08:00
|
|
|
It "Revision should be in correct range" -Skip:(!(Test-Elevated)) {
|
|
|
|
$pwshDllPath = Join-Path -Path $versionPath -ChildPath "pwsh.dll"
|
|
|
|
[version] $version = (Get-ChildItem $pwshDllPath).VersionInfo.FileVersion
|
|
|
|
Write-Verbose "pwsh.dll version: $version" -Verbose
|
|
|
|
$version.Revision | Should -BeGreaterOrEqual $revisionRange[0] -Because "$channel revision should between $($revisionRange[0]) and $($revisionRange[1])"
|
|
|
|
$version.Revision | Should -BeLessOrEqual $revisionRange[1] -Because "$channel revision should between $($revisionRange[0]) and $($revisionRange[1])"
|
|
|
|
}
|
|
|
|
|
2023-05-10 13:36:34 +08:00
|
|
|
It 'MSI should add ProductCode in registry' -Skip:(!(Test-Elevated)) {
|
|
|
|
|
|
|
|
$productCode = if ($msiUpgradeCode -eq '39243d76-adaf-42b1-94fb-16ecf83237c8' -or
|
|
|
|
$msiUpgradeCode -eq '31ab5147-9a97-4452-8443-d9709f0516e1') {
|
|
|
|
# x64
|
|
|
|
$regKeyPath | Should -Exist
|
|
|
|
Get-ItemPropertyValue -Path $regKeyPath -Name 'ProductCode'
|
|
|
|
} elseif ($msiUpgradeCode -eq '86abcfbd-1ccc-4a88-b8b2-0facfde29094' -or
|
|
|
|
$msiUpgradeCode -eq '1d00683b-0f84-4db8-a64f-2f98ad42fe06') {
|
|
|
|
# x86 - need to open the 32bit reghive
|
|
|
|
$wow32RegKey = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, [Microsoft.Win32.RegistryView]::Registry32)
|
|
|
|
$subKey = $wow32RegKey.OpenSubKey("Software\Microsoft\PowerShellCore\InstalledVersions\$msiUpgradeCode")
|
|
|
|
$subKey.GetValue("ProductCode")
|
|
|
|
}
|
|
|
|
|
|
|
|
$productCode | Should -Not -BeNullOrEmpty
|
|
|
|
$productCodeGuid = [Guid]$productCode
|
|
|
|
$productCodeGuid | Should -BeOfType "Guid"
|
|
|
|
$productCodeGuid.Guid | Should -Not -Be $msiUpgradeCode
|
|
|
|
}
|
|
|
|
|
2020-06-30 05:13:10 +08:00
|
|
|
It "MSI should uninstall without error" -Skip:(!(Test-Elevated)) {
|
|
|
|
{
|
|
|
|
Invoke-MsiExec -Uninstall -MsiPath $msiX64Path
|
|
|
|
} | Should -Not -Throw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-03 01:47:29 +08:00
|
|
|
Context "Add Path disabled" {
|
2021-12-07 05:18:44 +08:00
|
|
|
BeforeAll {
|
|
|
|
Set-UseMU -Value 0
|
|
|
|
}
|
|
|
|
|
|
|
|
It "UseMU should be 0 before install" -Skip:(!(Test-Elevated)) {
|
|
|
|
$useMu = Get-UseMU
|
|
|
|
$useMu | Should -Be 0
|
|
|
|
}
|
|
|
|
|
2018-04-03 01:47:29 +08:00
|
|
|
It "MSI should install without error" -Skip:(!(Test-Elevated)) {
|
|
|
|
{
|
2021-07-15 06:41:56 +08:00
|
|
|
Invoke-MsiExec -Install -MsiPath $msiX64Path -Properties @{ADD_PATH = 0; USE_MU = 1; ENABLE_MU = 1}
|
2018-04-03 01:47:29 +08:00
|
|
|
} | Should -Not -Throw
|
|
|
|
}
|
|
|
|
|
|
|
|
It "MSI should have not be updated path" -Skip:(!(Test-Elevated)) {
|
|
|
|
$psPath = ([System.Environment]::GetEnvironmentVariable('PATH', 'MACHINE')) -split ';' |
|
2021-02-09 05:25:14 +08:00
|
|
|
Where-Object { $_ -like '*files\powershell*' -and $_ -notin $beforePath }
|
2018-04-03 01:47:29 +08:00
|
|
|
|
|
|
|
$psPath | Should -BeNullOrEmpty
|
|
|
|
}
|
|
|
|
|
2021-07-15 06:41:56 +08:00
|
|
|
It "UseMU should be 1" -Skip:(!(Test-Elevated)) {
|
|
|
|
Invoke-TestAndUploadLogOnFailure -Test {
|
|
|
|
$useMu = Get-UseMU
|
|
|
|
$useMu | Should -Be 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
It "MSI should uninstall without error" -Skip:(!(Test-Elevated)) {
|
|
|
|
{
|
|
|
|
Invoke-MsiExec -Uninstall -MsiPath $msiX64Path
|
|
|
|
} | Should -Not -Throw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Context "USE_MU disabled" {
|
2021-12-07 05:18:44 +08:00
|
|
|
BeforeAll {
|
|
|
|
Set-UseMU -Value 0
|
|
|
|
}
|
|
|
|
|
|
|
|
It "UseMU should be 0 before install" -Skip:(!(Test-Elevated)) {
|
|
|
|
$useMu = Get-UseMU
|
|
|
|
$useMu | Should -Be 0
|
|
|
|
}
|
|
|
|
|
2021-07-15 06:41:56 +08:00
|
|
|
It "MSI should install without error" -Skip:(!(Test-Elevated)) {
|
|
|
|
{
|
|
|
|
Invoke-MsiExec -Install -MsiPath $msiX64Path -Properties @{USE_MU = 0}
|
|
|
|
} | Should -Not -Throw
|
|
|
|
}
|
|
|
|
|
|
|
|
It "UseMU should be 0" -Skip:(!(Test-Elevated)) {
|
|
|
|
Invoke-TestAndUploadLogOnFailure -Test {
|
|
|
|
$useMu = Get-UseMU
|
|
|
|
$useMu | Should -Be 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-03 01:47:29 +08:00
|
|
|
It "MSI should uninstall without error" -Skip:(!(Test-Elevated)) {
|
|
|
|
{
|
|
|
|
Invoke-MsiExec -Uninstall -MsiPath $msiX64Path
|
|
|
|
} | Should -Not -Throw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Context "Add Path enabled" {
|
|
|
|
It "MSI should install without error" -Skip:(!(Test-Elevated)) {
|
|
|
|
{
|
|
|
|
Invoke-MsiExec -Install -MsiPath $msiX64Path -Properties @{ADD_PATH = 1}
|
|
|
|
} | Should -Not -Throw
|
|
|
|
}
|
|
|
|
|
|
|
|
It "MSI should have updated path" -Skip:(!(Test-Elevated)) {
|
2021-02-09 05:25:14 +08:00
|
|
|
if ($channel -eq 'preview') {
|
|
|
|
$pattern = '*files*\powershell*\preview*'
|
|
|
|
} else {
|
|
|
|
$pattern = '*files*\powershell*'
|
|
|
|
}
|
|
|
|
|
2018-04-03 01:47:29 +08:00
|
|
|
$psPath = ([System.Environment]::GetEnvironmentVariable('PATH', 'MACHINE')) -split ';' |
|
2021-02-09 05:25:14 +08:00
|
|
|
Where-Object { $_ -like $pattern -and $_ -notin $beforePath }
|
|
|
|
|
|
|
|
if (!$psPath) {
|
|
|
|
([System.Environment]::GetEnvironmentVariable('PATH', 'MACHINE')) -split ';' |
|
|
|
|
Where-Object { $_ -notin $beforePath } |
|
|
|
|
ForEach-Object { Write-Verbose -Verbose $_ }
|
|
|
|
}
|
2018-04-03 01:47:29 +08:00
|
|
|
|
|
|
|
$psPath | Should -Not -BeNullOrEmpty
|
|
|
|
}
|
|
|
|
|
|
|
|
It "MSI should uninstall without error" -Skip:(!(Test-Elevated)) {
|
|
|
|
{
|
|
|
|
Invoke-MsiExec -Uninstall -MsiPath $msiX64Path
|
|
|
|
} | Should -Not -Throw
|
|
|
|
}
|
2023-03-07 05:18:34 +08:00
|
|
|
|
|
|
|
Context "Disable Telemetry" {
|
|
|
|
It "MSI should set POWERSHELL_TELEMETRY_OPTOUT env variable when MSI property DISABLE_TELEMETRY is set to 1" -Skip:(!(Test-Elevated)) {
|
|
|
|
try {
|
|
|
|
$originalValue = [System.Environment]::GetEnvironmentVariable('POWERSHELL_TELEMETRY_OPTOUT', [System.EnvironmentVariableTarget]::Machine)
|
|
|
|
[System.Environment]::SetEnvironmentVariable('POWERSHELL_TELEMETRY_OPTOUT', '0', [System.EnvironmentVariableTarget]::Machine)
|
|
|
|
{
|
|
|
|
Invoke-MsiExec -Install -MsiPath $msiX64Path -Properties @{DISABLE_TELEMETRY = 1 }
|
|
|
|
} | Should -Not -Throw
|
|
|
|
[System.Environment]::GetEnvironmentVariable('POWERSHELL_TELEMETRY_OPTOUT', [System.EnvironmentVariableTarget]::Machine) |
|
|
|
|
Should -Be 1
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
[System.Environment]::SetEnvironmentVariable('POWERSHELL_TELEMETRY_OPTOUT', $originalValue, [System.EnvironmentVariableTarget]::Machine)
|
|
|
|
{
|
|
|
|
Invoke-MsiExec -Uninstall -MsiPath $msiX64Path
|
|
|
|
} | Should -Not -Throw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
It "MSI should not change POWERSHELL_TELEMETRY_OPTOUT env variable when MSI property DISABLE_TELEMETRY not set" -Skip:(!(Test-Elevated)) {
|
|
|
|
try {
|
|
|
|
$originalValue = [System.Environment]::GetEnvironmentVariable('POWERSHELL_TELEMETRY_OPTOUT', [System.EnvironmentVariableTarget]::Machine)
|
|
|
|
[System.Environment]::SetEnvironmentVariable('POWERSHELL_TELEMETRY_OPTOUT', 'untouched', [System.EnvironmentVariableTarget]::Machine)
|
|
|
|
{
|
|
|
|
Invoke-MsiExec -Install -MsiPath $msiX64Path
|
|
|
|
} | Should -Not -Throw
|
|
|
|
[System.Environment]::GetEnvironmentVariable('POWERSHELL_TELEMETRY_OPTOUT', [System.EnvironmentVariableTarget]::Machine) |
|
|
|
|
Should -Be 'untouched'
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
[System.Environment]::SetEnvironmentVariable('POWERSHELL_TELEMETRY_OPTOUT', $originalValue, [System.EnvironmentVariableTarget]::Machine)
|
|
|
|
{
|
|
|
|
Invoke-MsiExec -Uninstall -MsiPath $msiX64Path
|
|
|
|
} | Should -Not -Throw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-03 01:47:29 +08:00
|
|
|
}
|
|
|
|
}
|