Как массовое разблокировать несколько файлов через power shell в windows

How to use Unblock-File cmdlet in PowerShell

Basic Syntax

Unblock-File -Path <Path-to-the-File>

Example

Unblock-File -Path C:\Downloads\setup.ps1

Confirming Unblock Actions

Unblock-File -Path C:\Downloads\*.ps1 -Confirm

Using the WhatIf Parameter

Unblock-File -Path C:\Downloads\*.ps1 -WhatIf

Unblock Multiple Files in PowerShell using Unblock-File cmdlet

Unblock-File -Path C:\Downloads\*.ps1
# PowerShell Script to Unblock Multiple Files
# Specify the directory path where the downloaded files are located
$directoryPath = "C:\Files"
# Retrieve all files in the directory
$files = Get-ChildItem -Path $directoryPath
# Iterate over each file and unblock it
foreach ($file in $files) { # Check if the file is blocked if ((Get-ItemProperty -Path $file.FullName -Name ZoneIdentifier -ErrorAction SilentlyContinue) -ne $null) { # Unblock the file Unblock-File -Path $file.FullName Write-Host "Unblocked: $($file.Name)" } else { Write-Host "Already unblocked: $($file.Name)" }
}
Write-Host "All files have been processed."

Here is the script explanation:

  • The script starts by setting a variable $directoryPath to the path where your downloaded files are located.
  • Get-ChildItem cmdlet is used to retrieve all the files in the specified directory.
  • foreach loop iterates over each file, and for each one, it checks if a ZoneIdentifier stream exists, which indicates that the file is blocked.
  • If the file is blocked, Unblock-File is used to unblock it, and a message is displayed in the console.
  • If the file is not blocked, a message indicating that it is already unblocked is displayed.
PowerShell unblock-file

Conclusion

You may also like:

Bijay Kumar

:/>  Как изменить настройки подсети