当试图从互联网机器上运行ps1文件时,取消阻止文件可以消除提示警告



我想在远程机器上根据exif数据重命名照片,代码如下:

Unblock-File -path ..exif-datetaken.ps1
Get-ChildItem *.jpg | foreach {
#Write-Host "$_`t->`t" -ForegroundColor Cyan -NoNewLine 
$date = (..exif-datetaken.ps1 $_.FullName)
if ($date -eq $null) {
Write-Host '{ No ''Date Taken'' in Exif }' -ForegroundColor Cyan    
return
}
$newName = $date.ToString('yyyy-MM-dd HH-mm-ss') + $_.extension
$newName = (Join-Path $_.DirectoryName $newName)
Write-Host $newName -ForegroundColor Cyan
mv $_ $newName
}

我使用解锁文件来消除警告,因为我需要手动点击按钮来确认每张照片,但我发现解锁文件不起作用,我仍然收到警告提示,

解决这个问题的方法不对吗?

您从web下载的几乎任何文件都会附带ADS(备用日期流(,这表明它来自web,不应受到信任。

你必须使用解锁文件来摆脱ADS.

如果你对很多下载的文件都这样做,那么在对它们采取任何其他操作之前,你必须对所有的文件都这么做。

ForEach ($TargetPath in $TargetPaths)
{
$TargetPath
Get-ChildItem -Path $TargetPath -Recurse | Unblock-File
Start-Sleep -Seconds 1
}
# Your rename code here

如果在下载任何文件后遇到提示,则可能需要根据需要实现-Confirm或-Force开关。

Unblock-File -Confirm:$false
Rename-Item -Confirm:$false

实际上,只有下载的文件才需要解除阻止。如果您收到其他提示,则表明文件存在某些锁定或权限问题。然而,由于您没有显示错误,我们只能猜测。

最新更新