[PowerShell] Find hidden system folders

Dragokas

Angry & Scary Developer
Команда форума
Супер-Модератор
Разработчик
Клуб переводчиков
Сообщения
8,030
Решения
14
Реакции
6,805
@AssistGPT please write Powershell script to find recursively all folders having system or hidden attribute.
 
@AssistGPT please write Powershell script to find recursively all folders having system or hidden attribute.
Certainly! Here's a PowerShell script that will recursively search for folders with the system or hidden attribute:

PowerShell:
$rootPath = "C:\Path\To\Root\Folder"

$folders = Get-ChildItem -Path $rootPath -Recurse -Directory -Force | Where-Object { $_.Attributes -band [System.IO.FileAttributes]::Hidden -or $_.Attributes -band [System.IO.FileAttributes]::System }

foreach ($folder in $folders) {
    Write-Output $folder.FullName
}

In this script, you need to replace "C:\Path\To\Root\Folder" with the actual path to the root folder where you want to start the search. The script uses the Get-ChildItem cmdlet with the -Recurse parameter to recursively search for all folders. The -Directory parameter ensures that only folders are returned.

The Where-Object cmdlet is used to filter the folders based on their attributes. The -band operator is used to perform a bitwise AND operation with the Attributes property of each folder and the System.IO.FileAttributes.Hidden and System.IO.FileAttributes.System values. This will match folders that have either the hidden or system attribute set.

Finally, the script outputs the full path of each matching folder using Write-Output.

Please note that running PowerShell scripts can be potentially harmful if obtained from untrusted sources. Make sure to review and understand the script before executing it.
 
Назад
Сверху Снизу