Z
Z
ZIK13372019-05-13 16:46:52
PowerShell
ZIK1337, 2019-05-13 16:46:52

Access denied when counting the volume of pictures in the Windows directory, although there were none before, how to fix it?

You need to get the total volume of all bmp, jpg files in the Winodws directory and all its subdirectories.

$sum=0; ForEach ($f in dir C:\Windows\* -include *.bmp, *.jpg -recurse){$sum+=$f.length} $sum

It used to work, but now there are a lot of access denials and it displays 0, even if I add the pictures myself to the Windows directory.
spoiler
c6l3V4O.jpg

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Artem @Jump, 2019-05-13
curated by the

See what permissions are on the files, from which user you are running the script.

N
NewDevLab, 2019-05-13
@NewDevLab

Run script as admin.

K
Konstantin Tsvetkov, 2019-05-14
@tsklab

Using Adjusting Token Privileges in Powershell , you increase administrator privileges and count without errors:

Set-ExecutionPolicy Unrestricted Process
Import-Module .\Set-LHSTokenPrivilege.ps1
Set-LHSTokenPrivilege SeBackupPrivilege
Set-LHSTokenPrivilege SeRestorePrivilege
$sum=0; ForEach ($f in dir C:\Windows\* -include *.bmp, *.jpg -recurse){$sum+=$f.length} $sum

После добавления в исключения 5cda328eceaf0177732986.png ваш скрипт всё подсчитал.
Если dir /q C:\Windows\System32\LogFiles\WMI показывает, у папки нет владельца, то есть
14.05.2019  13:10    <DIR>          NT AUTHORITY\СИСТЕМА   .
14.05.2019  13:10    <DIR>          NT AUTHORITY\СИСТЕМА   ..
11.05.2019  15:20    <DIR>          ...                    RtBackup
надо его восстановить
takeown /F C:\Windows\System32\LogFiles\WMI\RtBackup /A

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question