Skip to content

Commit 1333bc6

Browse files
committed
cherry-pick e81ce0e
1 parent 2b5b241 commit 1333bc6

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

Tasks/DeployVisualStudioTestAgent/InstallTestAgent.ps1

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function ExtractAgentArchive ($SetupArchive, $Destination) {
1+
function ExtractAgentArchive ($SetupArchive, $Destination) {
22
Write-Verbose "Extracting the archive $SetupArchive"
33
Try {
44
Add-Type -AssemblyName System.IO.Compression.FileSystem
@@ -25,9 +25,24 @@ function InstallTestAgent2017 {
2525
}
2626

2727
# First we need to install the certificates for TA 2017
28-
$SetupDir = Split-Path -Path $SetupPath
29-
Write-Verbose "Installing test agent certificates"
30-
Get-ChildItem -Path "$SetupDir\certificates\*.p12" -ErrorAction SilentlyContinue | Import-PfxCertificate -CertStoreLocation Cert:\CurrentUser\My -Exportable
28+
$SetupDir = Split-Path -Path $SetupPath
29+
30+
$osVersion = [environment]::OSVersion.Version
31+
$certFile = Get-ChildItem -Path "$SetupDir\certificates\*.p12" -ErrorAction SilentlyContinue
32+
if($certFile -and -not (Test-Path -Path $certFile))
33+
{
34+
Write-Verbose "Installing test agent certificates"
35+
if ($osVersion.Major -eq "6" -and $osVersion.Minor -eq "1") {
36+
## Windows 7 SP1. Import-PfxCertificate is not present in windows 7
37+
Import-PfxCertificateWin7 -FilePath $certFile.FullName -certRootStore "CurrentUser" -certStore "My"
38+
}
39+
else {
40+
Import-PfxCertificate -FilePath $certFile.FullName -CertStoreLocation Cert:\CurrentUser\My -Exportable
41+
}
42+
}
43+
else {
44+
Write-Verbose "No test agent certificate found."
45+
}
3146

3247
$p = New-Object System.Diagnostics.Process
3348
$Processinfo = New-Object System.Diagnostics.ProcessStartInfo
@@ -50,6 +65,25 @@ function InstallTestAgent2017 {
5065
return $p.ExitCode
5166
}
5267

68+
function Import-PfxCertificateWin7 {
69+
param
70+
(
71+
[Parameter (Mandatory=$true, ValueFromPipelineByPropertyName)]
72+
[String]$FilePath,
73+
[String]$certRootStore="CurrentUser",
74+
[String]$certStore="My"
75+
)
76+
Write-Verbose "Installing agent certificate for Windows 7."
77+
78+
$pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2
79+
$pfx.import($FilePath, $pfxPass, "Exportable")
80+
$store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore)
81+
$store.open("MaxAllowed")
82+
$store.add($pfx)
83+
$store.close()
84+
Write-Verbose "Successfully installed the agent certificate."
85+
}
86+
5387
function Install-Product($SetupPath, $ProductVersion, $Update) {
5488
$exitCode = 0
5589

Tasks/DeployVisualStudioTestAgent/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ To learn more about the general usage of the task, please see https://msdn.micro
66

77
### Prerequisites
88
The task requires:
9-
- .NET 4.6.1 on Windows8 or Windows 2K8R2
9+
- .NET 4.6.1 on Windows7 or Windows 2K8R2
1010
- Test machines should have PSRemoting enabled (run 'Enable-PSRemoting' on Windows Powershell)
1111
### WinRM setup
1212
This task uses the [Windows Remote Management](https://msdn.microsoft.com/en-us/library/aa384426.aspx) (WinRM) to access domain-joined or workgroup, on-premises physical or virtual machines.

Tasks/DeployVisualStudioTestAgent/TestAgentConfiguration.ps1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,29 @@
162162

163163
$rootFolder = $ScheduleObject.GetFolder('\') #'
164164
$newTask = $rootFolder.RegisterTaskDefinition("DTA", $TaskDefinition, 6, '', '', 3)
165+
Write-Verbose "Starting scheduled task on Windows 7." -Verbose
166+
167+
Start-Sleep -Seconds 30
168+
$p = Get-Process -Name "DTAExecutionHost"
169+
$rootFolder.DeleteTask("DTA", 0)
165170
}
166171
else {
167172
# Windows 8 or above
168173
$action = New-ScheduledTaskAction -Execute "$SetupPath\DTAExecutionHost.exe" -Argument $dtaArgs
169174
$trigger = New-ScheduledTaskTrigger -AtLogOn
170-
$exePath = "$SetupPath\DTAExecutionHost.exe $dtaArgs"
171175

172176
Unregister-ScheduledTask -TaskName "DTA" -Confirm:$false -OutVariable out -ErrorVariable err -ErrorAction SilentlyContinue | Out-Null
173177
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "DTA" -Description "DTA UI" -RunLevel Highest -OutVariable out -ErrorVariable err | Out-Null
174178
Write-Verbose "Registering scheduled task output: $out error: $err" -Verbose
175179

176180
Start-ScheduledTask -TaskName "DTA" -OutVariable out -ErrorVariable err | Out-Null
177181
Write-Verbose "Starting scheduled task output: $out error: $err" -Verbose
182+
183+
Start-Sleep -Seconds 30
184+
$p = Get-Process -Name "DTAExecutionHost"
178185
Unregister-ScheduledTask -TaskName "DTA" -Confirm:$false -ErrorAction SilentlyContinue
179186
}
180-
181-
Start-Sleep -Seconds 10
182187

183-
$p = Get-Process -Name "DTAExecutionHost" -ErrorAction SilentlyContinue
184188
if ($p) {
185189
return 0
186190
}

0 commit comments

Comments
 (0)