diff --git a/assets/wix/Product.wxs b/assets/wix/Product.wxs
index 54979ecb51c..674e67fc860 100644
--- a/assets/wix/Product.wxs
+++ b/assets/wix/Product.wxs
@@ -154,6 +154,7 @@
+
@@ -213,6 +214,10 @@
+
+ DISABLE_TELEMETRY
+
+
ADD_PATH=1
@@ -320,7 +325,8 @@
-
+
+
The application is distributed under the MIT license.]]>
diff --git a/test/packaging/windows/msi.tests.ps1 b/test/packaging/windows/msi.tests.ps1
index 0ee34ca482c..71254d287bc 100644
--- a/test/packaging/windows/msi.tests.ps1
+++ b/test/packaging/windows/msi.tests.ps1
@@ -301,5 +301,43 @@ Describe -Name "Windows MSI" -Fixture {
Invoke-MsiExec -Uninstall -MsiPath $msiX64Path
} | Should -Not -Throw
}
+
+ 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
+ }
+ }
+ }
}
}