Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Powershell file count problem


  • Please log in to reply
No replies to this topic

#1 ozzynotwood

ozzynotwood

  • Members
  • 30 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:04:53 PM

Posted 02 June 2018 - 02:39 AM

Hi everyone, I'm trying to get script to count the files in the recycle bin:

 

Write-Host (dir C:\$Recycle.Bin\ -recurse -file | measure).Count, "file(s) found in Recycle bin." -ForegroundColor Cyan;
Read-Host -Prompt “Press ENTER to exit”
 
Now I get the error:
 
dir : Access to the path 'C:\PerfLogs' is denied.
At X:\Automated Tasks\File count in recycle bin.ps1:1 char:13
+ Write-Host (dir C:\$Recycle.Bin\ -recurse -file | measure).Count, "fi ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\PerfLogs:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
 

 

I thought it might be the $ in the recycle bin path giving me the problem so I added a tilde:

 

Write-Host (dir C:\$Recycle.Bin\ -recurse -file | measure).Count, "file(s) found in Recycle bin." -ForegroundColor Cyan;
Read-Host -Prompt “Press ENTER to exit”

 

Now I get something that looks good:

 

0 file(s) found in Recycle bin.
Press ENTER to exit:
 
Problem is the count is wrong, you can have 50 files in the recycle bun & the script will return a result of 0. Can anybody correct this code for me?

 



BC AdBot (Login to Remove)

 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users