Powershell 将本地文件的大小与共享点上的文件进行比较

Powershell compare size of local file to file on 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" 方法是否 return 正是您要查找的内容。根据 ContentLength,您可能想要明确定义您的类型。我会尝试这样的事情:

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