Skip to content

Commit

Permalink
Resolve CNAME before creating a WinRM session - closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Majcica committed Mar 20, 2018
1 parent 8fbb8dd commit 4abd391
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The only requirement is PowerShell V5 installed both on the build server and on
* **Clean Target**: Checking this option will clean the destination folder prior to copying the files to it.
* **Copy Files in Parallel**: Checking this option will copy files to all the target machines in parallel, which can speed up the copying process.

### Version history
### Task version history

* 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: 26 additions & 2 deletions src/win-rm-file-copy/WinRmFileCopy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@ param()

Trace-VstsEnteringInvocation $MyInvocation

function Resolve-HostNameOrAddress
{
[CmdletBinding()]
param
(
[Parameter(Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[Alias('HostName','IPAddress','CNAME','cn')]
[string]$ComputerName = $env:COMPUTERNAME
)
BEGIN { }
PROCESS
{
if (-not ([bool]($ComputerName -as [ipaddress])))
{
$ComputerName = ([System.Net.Dns]::GetHostAddresses($ComputerName)).IPAddressToString
}

$host1 = [System.Net.Dns]::GetHostbyAddress($ComputerName)

return $host1.HostName
}
END {}
}

try
{
# Get inputs for the task
Expand All @@ -15,7 +39,7 @@ 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 @@ -53,7 +77,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() } }
$machines = $machineNames.split(',') | ForEach-Object { if ($_ -and $_.trim()) { $_.trim() } } | Resolve-HostNameOrAddress

$secureAdminPassword = ConvertTo-SecureString $adminPassword -AsPlainText -Force
$machineCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminUserName, $secureAdminPassword
Expand Down
2 changes: 1 addition & 1 deletion src/win-rm-file-copy/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": "2",
"Minor": "0",
"Patch": "1"
"Patch": "2"
},
"minimumAgentVersion": "1.104.0",
"groups": [
Expand Down

0 comments on commit 4abd391

Please sign in to comment.