Foreach remove-item help

So I don’t have to keep pulling from a txt file that I create by export servers since I want this to run every 30 days.

$computers = Get-ADComputer - SearchBase ‘OU=Test,DC=Test,DC=COM’ -filter * | select -expand name
ForEach($computers in $computers)
{
Remove-Item c:\windows\ccmcache* -Force -recure

I guess you want to do something along the lines of

Thank you that worked. I so appreciate the help I was trying all different ways and none was working.

The C$ is missing from the path. You will need to possibly escape the $ with a backtick (`) like \C`$\ or I prefer a string format:

$computers = Get-ADComputer –SearchBase 'OU=Test,DC=Test,DC=COM' -filter * 
 ForEach($computer in $computers) {
    $path = "\\{0}\c$\windows\ccmcache\*" -f $computer.name
    Remove-Item $path -Force -recure
 }

yep I added that to the path and it’s working for me now, thanks