Hi, I’m in the process of creating a script that will automatically delete content older than 30 days in all recycle bins on every hard drive except certain .ini files. But here I come across some errors when I’m trying to list the contents of the recycle bin with “Get-ChildItem”. In the following code you will find what I already have. Here is the first pure attempt to display a list of the contents.
For your information: I have been programming with Powershell for only 2 weeks. Before I had no contact to this language. Therefore, I thank you already once for your consideration.
[quote quote=165544]Good start, can you update the thread with the error message you get .
[/quote]
Hello, below you will find the error message which I receive. For information drive “D” is a CD drive in this case.
Get-ChildItem : Der Pfad "D:\$Recycle.Bin\S" kann nicht gefunden werden, da er nicht
vorhanden ist.
In Zeile:6 Zeichen:9
+ $test = Get-ChildItem $Path -Force -Recurse -Exclude $exclude | Where ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (D:\$Recycle.Bin\S:String) [Get-ChildIt
em], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItem
Command
From a quick look, “D:$Recycle.Bin\S” will not be having the value you assume, whatever starts with $ is considered as a variable (here resulting in D:.Bin\S as $Recycle is not defined) when not escaped or not wrapped in single quotes, hence use single quotes