Skip to content

Commit

Permalink
Fixed reverse DNS issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Majcica committed Mar 21, 2018
1 parent 052c49d commit 61a746e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
28 changes: 15 additions & 13 deletions task/WinRmFileCopy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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('"')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -227,4 +229,4 @@ catch
finally
{
Trace-VstsLeavingInvocation $MyInvocation
}
}
2 changes: 1 addition & 1 deletion task/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": "2",
"Minor": "0",
"Patch": "2"
"Patch": "5"
},
"minimumAgentVersion": "1.104.0",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion vss-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 61a746e

Please sign in to comment.