Powershell将本地文件的大小与sharepoint上的文件进行比较

Powershell将本地文件的大小与sharepoint上的文件进行比较,powershell,powershell-3.0,Powershell,Powershell 3.0,我正在使用当前代码从sharepoint下载文件 $webClient = New-Object System.Net.WebClient $webClient.UseDefaultCredentials = $true $webClient.DownloadFile($sharepointPathFile, $localPathFile) | Out-Null 但是如果我想检查文件是否已经在本地位置,大小是否匹配或不同呢?我将如何使用powershell执行此操作 更新 这是我能得到的最接近

我正在使用当前代码从sharepoint下载文件

$webClient = New-Object System.Net.WebClient
$webClient.UseDefaultCredentials = $true
$webClient.DownloadFile($sharepointPathFile, $localPathFile) | Out-Null
但是如果我想检查文件是否已经在本地位置,大小是否匹配或不同呢?我将如何使用powershell执行此操作

更新 这是我能得到的最接近的

$url = $sharepointPathFile
$clnt = [System.Net.WebRequest]::Create($url)
$resp = $clnt.GetResponse()
$fileSize = $resp.ContentLength
Write-Host $fileSize
但我得到了以下错误:

Exception calling "GetResponse" with "0" argument(s): "The remote server returned an error: (401) Unauthorized."
At C:\Scripts\Tests\testCheckUpdatedSearchFiles.ps1:345 char:2
+     $resp = $clnt.GetResponse()
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException
我有完整的阅读和下载权限,所以这里还有其他不正确的地方吗?

我不确定“GetResponse”方法是否会返回您想要的内容。根据ContentLength,您可能需要显式定义类型。我想试试这样的东西:

$webClient = New-Object System.Net.WebClient
$webClient.OpenRead("path/to/file")
[Int64]$fileSize = $webClient.ResponseHeaders["Content-Length"]
Write-Host $fileSize

根据你的历史活动,我猜在你自己做了一些研究之后,你会在一点时间内回答你自己的问题…对不起,但这次看起来我真的被卡住了。。。我真的不熟悉sharepoints的工作,我的职责是确保我在这里什么都不是(这使得开发脚本变得困难)。