Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Delete hidden files starting with ~$?

$
0
0

I am trying to run a script on user folders to cleanup .tmp files and office temp files that start with ~$ that are hidden.  Here is my script:

$SourceDir = "\\Server\Students\"

foreach ($file in Get-ChildItem -Force $SourceDir -Recurse)
{
if (($file.Extension -match ".tmp") -or ($file.Name -like "~$*"))
	{
	Remove-Item $file.FullName -Force | Out-Null
	}
}

It seems to work fine for the .tmp files but doesn't seem to work at all on the ~$ files? I know they are hidden so I added -Force on Get-ChildItem but still no luck. I am sure it is something simple, but any hints?

Viewing all articles
Browse latest Browse all 2562

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>