PowerShell脚本忽略<whitespace> H的文件

时间:2017-09-21 14:24:06

标签: powershell

我从我的前身继承了这个脚本,它应该将一堆文件从一个位置复制到一个JFrog Artifactory中。

除了名称后跟H的文件外,它的工作正常。

例如,Test My Client.exe将被正确复制,但脚本将忽略Test My Host.exe

任何人都知道这种奇怪行为的原因是什么?

param
(
    [string]$RootPath="D:\_temp\upload\",
    [string]$Repo="repo-snapshot",
    [string]$Product="SEARCHER",
    [string]$Version="1.23.45678.9012",
    [string]$ArtifactoryRoot    
)
$AF_USER = "myUser"
$AF_PWD = "pA55VVoRd" #ConvertTo-SecureString "pA55VVoRd" -AsPlainText -Force  
$CREDS = New-Object System.Management.Automation.PSCredential ($AF_USER, $AF_PWD)  
$MajorMinor = $Version.Split('.')[0] + "." + $Version.Split('.')[1]
$BuildRevision = $Version.Split('.')[2] + "." + $Version.Split('.')[3]
$uri = "https://artifactory.test.com/artifactory/$Repo/TEST/$Product/$MajorMinor/$BuildRevision/$ArtifactoryRoot/"
$curl = "$PSScriptRoot\..\..\bin\ReleaseU\curl.exe"
Write-Host $MajorMinor
write-host $BuildRevision

$filesToUpload = Get-ChildItem $RootPath -Recurse -File

foreach($file in $filesToUpload)
{
    $artifactoryAddPath = $file.FullName.Remove(0,$RootPath.Length).Replace('\','/')
    $completeUrl = $uri+$artifactoryAddPath
    write-host $completeUrl

    $FileSize = (Get-Item $file.FullName).Length /1MB
    Write-Host "Filesize: "$FileSize" MB"
    $preTime = Get-Date

    write-host "$curl --user $AF_USER`:$AF_PWD --upload-file " $file.FullName "$completeUrl --insecure"
    . $curl --user $AF_USER`:$AF_PWD --upload-file $file.FullName $completeUrl --insecure

    $postTime = Get-Date
    Write-Host "Upload finished"
    $timeDiff = $postTime - $preTime
    $avgSpeed = $FileSize / $timeDiff.TotalSeconds
    Write-Host -Object ("Upload speed is: {0:N2}MB/sec" -f ($avgSpeed));

}

0 个答案:

没有答案