簡體   English   中英

嘗試從Internet機運行ps1文件時,unblock-file可以擺脫提示警告

[英]unblock-file can get rid of prompt warning when try to run ps1 file from internet machine

我想根據我的遠程計算機上的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
}

我使用unblock-file擺脫警告,因為我需要單擊按鈕手動確認每張照片,但是我發現unblock-file不起作用,我仍然收到該警告提示,

解決此問題的方法是否錯誤?

您從網上下載的幾乎所有文件都將附加ADS(備用日期流),這表明該文件來自網絡,因此不值得信任。

您必須使用Unblock-File擺脫該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

取消鎖定實際上僅適用於下載的文件。 如果您收到其他提示,則說明文件已鎖定或存在權限問題。 但是,由於您沒有顯示錯誤,因此我們只能猜測。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM