diff --git a/Tasks/DeployVisualStudioTestAgent/InstallTestAgent.ps1 b/Tasks/DeployVisualStudioTestAgent/InstallTestAgent.ps1 index 8cce02a65ba3..25ed4ed95a75 100644 --- a/Tasks/DeployVisualStudioTestAgent/InstallTestAgent.ps1 +++ b/Tasks/DeployVisualStudioTestAgent/InstallTestAgent.ps1 @@ -1,4 +1,4 @@ -function ExtractAgentArchive ($SetupArchive, $Destination) { +function ExtractAgentArchive ($SetupArchive, $Destination) { Write-Verbose "Extracting the archive $SetupArchive" Try { Add-Type -AssemblyName System.IO.Compression.FileSystem @@ -25,9 +25,29 @@ function InstallTestAgent2017 { } # First we need to install the certificates for TA 2017 - $SetupDir = Split-Path -Path $SetupPath - Write-Verbose "Installing test agent certificates" - Get-ChildItem -Path "$SetupDir\certificates\*.p12" -ErrorAction SilentlyContinue | Import-PfxCertificate -CertStoreLocation Cert:\CurrentUser\My -Exportable + $SetupDir = Split-Path -Path $SetupPath + $certFiles = Get-ChildItem -Path "$SetupDir\certificates\*.p12" -ErrorAction SilentlyContinue + if($certFiles -and $certFiles.Length -gt 0) + { + $osVersion = [environment]::OSVersion.Version + Write-Verbose "Installing test agent certificates" -Verbose + if ($osVersion.Major -eq "6" -and $osVersion.Minor -eq "1") { + ## Windows 7 SP1. Import-PfxCertificate is not present in windows 7 + Write-Verbose "Installing agent certificate(s) for Windows 7." -Verbose + foreach($certFile in $certFiles) + { + Import-PfxCertificateWin7 -FilePath $certFile.FullName -CertRootStore "CurrentUser" -CertStore "My" + } + } + else { + Write-Verbose "Installing agent certificate(s) for Windows 8 or above." -Verbose + $certFiles | Import-PfxCertificate -CertStoreLocation Cert:\CurrentUser\My -Exportable + } + Write-Verbose "Successfully installed the agent certificate." -Verbose + } + else { + Write-Verbose "No test agent certificate found." -Verbose + } $p = New-Object System.Diagnostics.Process $Processinfo = New-Object System.Diagnostics.ProcessStartInfo @@ -50,6 +70,22 @@ function InstallTestAgent2017 { return $p.ExitCode } +function Import-PfxCertificateWin7 { + param + ( + [Parameter (Mandatory=$true, ValueFromPipelineByPropertyName)] + [String]$FilePath, + [String]$CertRootStore="CurrentUser", + [String]$CertStore="My" + ) + $pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2 + $pfx.import($FilePath, $pfxPass, "Exportable") + $store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore) + $store.open("MaxAllowed") + $store.add($pfx) + $store.close() +} + function Install-Product($SetupPath, $ProductVersion, $Update) { $exitCode = 0 diff --git a/Tasks/DeployVisualStudioTestAgent/README.md b/Tasks/DeployVisualStudioTestAgent/README.md index 377bb264b424..276c7b973c96 100644 --- a/Tasks/DeployVisualStudioTestAgent/README.md +++ b/Tasks/DeployVisualStudioTestAgent/README.md @@ -6,7 +6,8 @@ To learn more about the general usage of the task, please see https://msdn.micro ### Prerequisites The task requires: -- .NET 4.6.1 on Windows8 or Windows 2K8R2 +- .NET 4.6.1 on Windows7 or Windows 2K8R2 +- PowerShell 3 or newer - Test machines should have PSRemoting enabled (run 'Enable-PSRemoting' on Windows Powershell) ### WinRM setup 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. diff --git a/Tasks/DeployVisualStudioTestAgent/TestAgentConfiguration.ps1 b/Tasks/DeployVisualStudioTestAgent/TestAgentConfiguration.ps1 index 95f10d788b58..ab31c66a84c1 100644 --- a/Tasks/DeployVisualStudioTestAgent/TestAgentConfiguration.ps1 +++ b/Tasks/DeployVisualStudioTestAgent/TestAgentConfiguration.ps1 @@ -162,12 +162,15 @@ $rootFolder = $ScheduleObject.GetFolder('\') #' $newTask = $rootFolder.RegisterTaskDefinition("DTA", $TaskDefinition, 6, '', '', 3) + Write-Verbose "Starting scheduled task on Windows 7." -Verbose + Start-Sleep -Seconds 30 + $p = Get-Process -Name "DTAExecutionHost" + $rootFolder.DeleteTask("DTA", 0) } else { # Windows 8 or above $action = New-ScheduledTaskAction -Execute "$SetupPath\DTAExecutionHost.exe" -Argument $dtaArgs $trigger = New-ScheduledTaskTrigger -AtLogOn - $exePath = "$SetupPath\DTAExecutionHost.exe $dtaArgs" Unregister-ScheduledTask -TaskName "DTA" -Confirm:$false -OutVariable out -ErrorVariable err -ErrorAction SilentlyContinue | Out-Null Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "DTA" -Description "DTA UI" -RunLevel Highest -OutVariable out -ErrorVariable err | Out-Null @@ -175,12 +178,12 @@ Start-ScheduledTask -TaskName "DTA" -OutVariable out -ErrorVariable err | Out-Null Write-Verbose "Starting scheduled task output: $out error: $err" -Verbose + + Start-Sleep -Seconds 30 + $p = Get-Process -Name "DTAExecutionHost" Unregister-ScheduledTask -TaskName "DTA" -Confirm:$false -ErrorAction SilentlyContinue } - - Start-Sleep -Seconds 10 - $p = Get-Process -Name "DTAExecutionHost" -ErrorAction SilentlyContinue if ($p) { return 0 } diff --git a/Tasks/DeployVisualStudioTestAgent/task.json b/Tasks/DeployVisualStudioTestAgent/task.json index fc82450542db..9171adcda89f 100644 --- a/Tasks/DeployVisualStudioTestAgent/task.json +++ b/Tasks/DeployVisualStudioTestAgent/task.json @@ -13,7 +13,7 @@ "version": { "Major": 2, "Minor": 1, - "Patch": 7 + "Patch": 8 }, "runsOn": [ "Agent" diff --git a/Tasks/DeployVisualStudioTestAgent/task.loc.json b/Tasks/DeployVisualStudioTestAgent/task.loc.json index 4f9c8bc27f0e..1f5ca96c57a9 100644 --- a/Tasks/DeployVisualStudioTestAgent/task.loc.json +++ b/Tasks/DeployVisualStudioTestAgent/task.loc.json @@ -13,7 +13,7 @@ "version": { "Major": 2, "Minor": 1, - "Patch": 7 + "Patch": 8 }, "runsOn": [ "Agent"