Hello,
I've been trying to create a script which uses a .txt file as a source of computers (in domain environment) and deletes temporary files from them using $env:temp and/or $env:windir\temp. So basically delete temps ("%userprofile%\Local Settings\Temp" and %windir%\temp) from a huge amount of computers.
I'm very new to powershelling and I've only performed some simple tasks using PS. I've tried something like this to start with:
$computers = Get-Content "C:\Temp\computers.txt"
ForEach ($MachineName In $computers){
$tempfolder = Get-ChildItem -Path "\\$MachineName\c$\Windows\Temp"
Let's stop there, is it possible to automatically point script to delete files from target machines using $env:temp? If I use "\\$MachineName\$env:Temp" it doesn't obviously work.
I can figure the Remove-Item part myself, but I can't figure out how to use $env:temp to automatically point to each computers' user profiles' temp / windows' temp.
Any tips are welcome!
↧