cosine83

Delete FNTCACHE.DAT

Aug 15th, 2014
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Import-Module activedirectory
  2.  
  3. $searchbase = "OU=test,OU=test,DC=domain,DC=com"
  4.  
  5. $query = Get-ADComputer -Filter * -SearchBase $searchbase | Select Name | Sort Name
  6. $computers = $query.Name
  7.  
  8. foreach ($computer in $computers)
  9. {
  10.     Write-Host "Connecting..."
  11.     If(Test-Connection $computer -Count 1 -Quiet) #Check that PC is online
  12.     {
  13.         If(Test-WSMan $computer) #PC is online so check if WinRM enabled
  14.         {
  15.             #WinRM is enabled, delete file via Invoke-Command
  16.             Write-Host "WinRM is enabled on $computer, proceeding..."
  17.             Write-Host "$computer - Deleting files via WinRM!"
  18.             Invoke-Command -ComputerName $computer -ScriptBlock {Remove-Item -Path "C:\Windows\System32\FNTCACHE.DAT" -Recurse -Force}
  19.             Write-Host -ForegroundColor Green "$computer - Done!"
  20.         }
  21.         else
  22.         {
  23.             #WinRM not enabled, delete file via UNC path
  24.             $file = "\\$($computer)\c$\Windows\System32\FNTCACHE.DAT"
  25.             Write-Host "WinRM is not enabled on $computer, proceeding..."
  26.             Write-Host "$computer - Deleting files via UNC!"
  27.             Remove-Item $file -force -recurse
  28.             Write-Host -ForegroundColor Green "$computer - Done!"
  29.         }
  30.     }
  31.     else
  32.     {
  33.         #PC was offline
  34.         Write-Host -ForegroundColor Red "$computer - Offline!"
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment