diff --git a/README.md b/README.md index 07fd902..16e3b09 100644 --- a/README.md +++ b/README.md @@ -28,5 +28,6 @@ Feel free to notify any issue in the issues section of this GitHub repository. I ## Task version history +* 2.0.5 - Solved the issues introduced with v2.0.2 where reverse lookup data in DNS is not present * 2.0.2 - Resolve CNAME before creating a WinRM session ([#2](https://github.com/mmajcica/win-rm-file-copy/issues/2)) * 2.0.1 - Implements the Skip CA Check for HTTPS with a self signed certificate ([#1](https://github.com/mmajcica/win-rm-file-copy/issues/1)) \ No newline at end of file diff --git a/task/WinRmFileCopy.ps1 b/task/WinRmFileCopy.ps1 index 193ce83..41f5fda 100644 --- a/task/WinRmFileCopy.ps1 +++ b/task/WinRmFileCopy.ps1 @@ -12,15 +12,17 @@ function Resolve-HostNameOrAddress [Alias('HostName','IPAddress','CNAME','cn')] [string]$ComputerName = $env:COMPUTERNAME ) - BEGIN { } + BEGIN { Write-Verbose "Invoked Resolve-HostNameOrAddress with ComputerName = '$ComputerName'" } PROCESS { - if (-not ([bool]($ComputerName -as [ipaddress]))) + if ([bool]($ComputerName -as [ipaddress])) { - $ComputerName = ([System.Net.Dns]::GetHostAddresses($ComputerName)).IPAddressToString + $host1 = [System.Net.Dns]::GetHostEntry($ComputerName) + } + else + { + $host1 = [System.Net.Dns]::GetHostByName($ComputerName) } - - $host1 = [System.Net.Dns]::GetHostbyAddress($ComputerName) return $host1.HostName } @@ -39,7 +41,6 @@ try [bool]$copyFilesInParallel = Get-VstsInput -Name CopyFilesInParallel -AsBool [bool]$useSsl = Get-VstsInput -Name UseSsl -AsBool [bool]$TestCertificate = Get-VstsInput -Name TestCertificate -AsBool - [bool]$verbose = Get-VstsTaskVariable -Name "System.Debug" -AsBool $sourcePath = $sourcePath.Trim('"') @@ -77,7 +78,7 @@ try Write-Output "Files from '$sourcePath' will be copied to the path '$targetPath' on the remote machine(s)." - $machines = $machineNames.split(',') | ForEach-Object { if ($_ -and $_.trim()) { $_.trim() } } | Resolve-HostNameOrAddress + $machines = $machineNames.split(',') | ForEach-Object { if ($_ -and $_.trim()) { $_.trim() } } $secureAdminPassword = ConvertTo-SecureString $adminPassword -AsPlainText -Force $machineCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminUserName, $secureAdminPassword @@ -113,7 +114,8 @@ try $session = New-PSSession -ComputerName $fqdn -Credential $credential -UseSSL:$useSsl -Port $port } - $testPath = { + $testPath = + { param ([string]$targetPath) if (-not (Test-Path -LiteralPath $targetPath -IsValid -PathType Container)) @@ -152,12 +154,12 @@ try if ($items.Count -gt 1) { - $machineName = $items[0] + $machineName = Resolve-HostNameOrAddress -ComputerName $items[0] $machinePort = $items[1] } else { - $machineName = $items[0] + $machineName = Resolve-HostNameOrAddress -ComputerName $items[0] $machinePort = 5985 if ($useSsl) @@ -181,12 +183,12 @@ try if ($items.Count -gt 1) { - $machineName = $items[0] + $machineName = Resolve-HostNameOrAddress -ComputerName $items[0] $machinePort = $items[1] } else { - $machineName = $items[0] + $machineName = Resolve-HostNameOrAddress -ComputerName $items[0] $machinePort = 5985 if ($useSsl) @@ -227,4 +229,4 @@ catch finally { Trace-VstsLeavingInvocation $MyInvocation -} \ No newline at end of file +} diff --git a/task/task.json b/task/task.json index d1c6699..fe98ca0 100644 --- a/task/task.json +++ b/task/task.json @@ -14,7 +14,7 @@ "version": { "Major": "2", "Minor": "0", - "Patch": "2" + "Patch": "5" }, "minimumAgentVersion": "1.104.0", "groups": [ diff --git a/vss-extension.json b/vss-extension.json index 5356b44..6d57cfa 100644 --- a/vss-extension.json +++ b/vss-extension.json @@ -2,7 +2,7 @@ "manifestVersion": 1, "extensionId": "win-rm-file-copy", "name": "WinRm File Copy", - "version": "1.0.5", + "version": "1.0.6", "publisher": "mmajcica", "description": "Windows Machine File Copy (WinRM)", "public": false,