Differences

This shows you the differences between the selected revisions of the page.

2017-04-16 2017-10-03
Placing ad (Petr) using variable expansion in strings in powershell (martin)
Line 44: Line 44:
        if (!$remoteChecksumAlg -or ($remoteChecksumAlg -eq "local"))         if (!$remoteChecksumAlg -or ($remoteChecksumAlg -eq "local"))
        {         {
-            Write-Host ("Downloading file {0}..." -f $remotePath)+            Write-Host "Downloading file $remotePath..."
            # Download file             # Download file
            $localPath = [System.IO.Path]::GetTempFileName()             $localPath = [System.IO.Path]::GetTempFileName()
Line 55: Line 55:
                $stream.Dispose()                 $stream.Dispose()
                               
-                Write-Host ("Downloaded file {0} checksum is {1}" -f $remotePath, $checksum)+                Write-Host "Downloaded file $remotePath checksum is $checksum"
                Remove-Item $localPath                 Remove-Item $localPath
Line 61: Line 61:
            else             else
            {             {
-                Write-Host ("Error downloading file {0}: {1}" -f $remotePath, $transferResult.Failures[0])+                Write-Host "Error downloading file $remotePath: $($transferResult.Failures[0])"
                $checksum = $False                 $checksum = $False
            }             }
Line 67: Line 67:
        else         else
        {         {
-            Write-Host ("Request checksum for file {0}..." -f $remotePath)+            Write-Host "Request checksum for file $remotePath..."
            $checksum = [System.BitConverter]::ToString($session.CalculateFileChecksum($remoteChecksumAlg, $remotePath))             $checksum = [System.BitConverter]::ToString($session.CalculateFileChecksum($remoteChecksumAlg, $remotePath))
-            Write-Host ("File {0} checksum is {1}" -f $remotePath, $checksum)+            Write-Host "File $remotePath checksum is $checksum"
        }         }
Line 99: Line 99:
        # Handle errors when enumerating the files         # Handle errors when enumerating the files
        $session.add_Failed( {         $session.add_Failed( {
-            Write-Host ("Error: {0}" -f $_.Error.Message)·+            Write-Host "Error: $($_.Exception.Message)"
        } )         } )
Line 112: Line 112:
        foreach ($fileInfo in $files)         foreach ($fileInfo in $files)
        {         {
-            Write-Host ("Found file {0} with size {1}" -f $fileInfo.FullName, $fileInfo.Length)+            Write-Host "Found file $($fileInfo.FullName) with size $($fileInfo.Length)"
            if ($sizes.ContainsKey($fileInfo.Length))             if ($sizes.ContainsKey($fileInfo.Length))
Line 124: Line 124:
                    if ($checksum -eq $otherChecksum)                     if ($checksum -eq $otherChecksum)
                    {                     {
-                        Write-Host ("Checksums of files {0} and {1} are identical" -f $fileInfo.FullName, $otherFilePath)+                        Write-Host "Checksums of files $($fileInfo.FullName) and $($otherFilePath) are identical"
                        $duplicates[$fileInfo.FullName] = $otherFilePath                         $duplicates[$fileInfo.FullName] = $otherFilePath
                    }                     }
Line 152: Line 152:
        foreach ($path1 in $duplicates.Keys)         foreach ($path1 in $duplicates.Keys)
        {         {
-            Write-Host ("{0} <=> {1}" -f $path1, $duplicates[$path1])+            Write-Host "$path1 <=> $($duplicates[$path1])"
        }         }
    }     }
Line 164: Line 164:
catch [Exception] catch [Exception]
{ {
-    Write-Host ("Error: {0}" -f $_.Exception.Message)+    Write-Host "Error: $($_.Exception.Message)"
    $result = 1     $result = 1
} }

Last modified: by martin