Skip to content

Commit 48779e9

Browse files
author
Eric Boersma
committed
fixed issues mentioned in PR
1 parent 66222c8 commit 48779e9

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

DSCResources/MSFT_xRemoteFile/MSFT_xRemoteFile.psm1

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ function Get-TargetResource
6262

6363
if ($ChecksumType -ine 'None')
6464
{
65-
$checksumValue = (Get-FileHash -Path $DestinationPath -Algorithm $ChecksumType).Hash
65+
$getFileHash = Get-FileHash -Path $DestinationPath -Algorithm $ChecksumType
66+
$checksumValue = $getFileHash.Hash
6667
}
6768
}
6869

@@ -81,7 +82,8 @@ function Get-TargetResource
8182

8283
if ($ChecksumType -ine 'None')
8384
{
84-
$checksumValue = (Get-FileHash -Path $expectedDestinationPath -Algorithm $ChecksumType).Hash
85+
$getFileHash = Get-FileHash -Path $expectedDestinationPath -Algorithm $ChecksumType
86+
$checksumValue = $getFileHash.Hash
8587
}
8688
}
8789
}
@@ -269,18 +271,7 @@ function Set-TargetResource
269271
$DestinationPath = Join-Path -Path $DestinationPath -ChildPath $uriFileName
270272
}
271273

272-
<#
273-
If checksum is needed create splat for Get-FileHash and an alternate variables for the
274-
checksum as the PSBoundParameters need to be removed as they are not parameters of Invoke-WebRequest
275-
#>
276-
if ($ChecksumType -ine 'None' -and -not [string]::IsNullOrEmpty($Checksum))
277-
{
278-
$fileHashSplat = @{
279-
Path = $DestinationPath
280-
Algorithm = $ChecksumType
281-
}
282-
$checksumValue = $Checksum
283-
}
274+
# Remove ChecksumType and Checksum from parameters as they are not parameters of Invoke-WebRequest.
284275
$null = $PSBoundParameters.Remove('ChecksumType')
285276
$null = $PSBoundParameters.Remove('Checksum')
286277

@@ -353,13 +344,20 @@ function Set-TargetResource
353344
}
354345

355346
# Check checksum
356-
if (-not [string]::IsNullOrEmpty($checksumValue))
347+
if ($ChecksumType -ine 'None' -and -not [String]::IsNullOrEmpty($Checksum))
357348
{
358-
$fileHash = (Get-FileHash @fileHashSplat).Hash
359-
if ($fileHash -ine $checksumValue)
349+
$fileHashSplat = @{
350+
Path = $DestinationPath
351+
Algorithm = $ChecksumType
352+
}
353+
354+
$getFileHash = Get-FileHash @fileHashSplat
355+
$fileHash = $getFileHash.Hash
356+
357+
if ($fileHash -ine $Checksum)
360358
{
361359
# the checksum failed
362-
$errorMessage = $script:localizedData.ChecksumDoesNotMatch -f $checksumValue, $fileHash
360+
$errorMessage = $script:localizedData.ChecksumDoesNotMatch -f $Checksum, $fileHash
363361
New-InvalidDataException `
364362
-ErrorId 'ChecksumDoesNotMatch' `
365363
-ErrorMessage $errorMessage
@@ -516,22 +514,23 @@ function Test-TargetResource
516514
}
517515

518516
if ($ChecksumType -ine 'None' `
519-
-and -not [string]::IsNullOrEmpty($Checksum) `
517+
-and -not [String]::IsNullOrEmpty($Checksum) `
520518
-and $fileExists -eq $true)
521519
{
522520
$fileHashSplat = @{
523521
Path = $DestinationPath
524522
Algorithm = $ChecksumType
525523
}
526-
$fileHash = (Get-FileHash @fileHashSplat).Hash
524+
$getFileHash = Get-FileHash @fileHashSplat
525+
$fileHash = $getFileHash.Hash
527526

528527
if ($fileHash -ieq $Checksum)
529528
{
530529
$fileExists = $true
531530
}
532531
else
533532
{
534-
# The checksum does not match. The file may match what is in the cached data. resetting it to false
533+
# The checksum does not match. The file may match what is in the cached data. Resetting it to false.
535534
$fileExists = $false
536535
}
537536
}
@@ -567,22 +566,23 @@ function Test-TargetResource
567566
}
568567

569568
if ($ChecksumType -ine 'None' `
570-
-and -not [string]::IsNullOrEmpty($Checksum) `
569+
-and -not [String]::IsNullOrEmpty($Checksum) `
571570
-and $fileExists -eq $true)
572571
{
573572
$fileHashSplat = @{
574573
Path = $expectedDestinationPath
575574
Algorithm = $ChecksumType
576575
}
577-
$fileHash = (Get-FileHash @fileHashSplat).Hash
576+
$getFileHash = Get-FileHash @fileHashSplat
577+
$fileHash = $getFileHash.Hash
578578

579579
if ($fileHash -ieq $Checksum)
580580
{
581581
$fileExists = $true
582582
}
583583
else
584584
{
585-
# The checksum does not match. The file may match what is in the cached data. resetting it to false
585+
# The checksum does not match. The file may match what is in the cached data. Resetting it to false.
586586
$fileExists = $false
587587
}
588588
}

0 commit comments

Comments
 (0)