Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module activedirectory
- $searchbase = "OU=test,OU=test,DC=domain,DC=com"
- $query = Get-ADComputer -Filter * -SearchBase $searchbase | Select Name | Sort Name
- $computers = $query.Name
- foreach ($computer in $computers)
- {
- Write-Host "Connecting..."
- If(Test-Connection $computer -Count 1 -Quiet) #Check that PC is online
- {
- If(Test-WSMan $computer) #PC is online so check if WinRM enabled
- {
- #WinRM is enabled, delete file via Invoke-Command
- Write-Host "WinRM is enabled on $computer, proceeding..."
- Write-Host "$computer - Deleting files via WinRM!"
- Invoke-Command -ComputerName $computer -ScriptBlock {Remove-Item -Path "C:\Windows\System32\FNTCACHE.DAT" -Recurse -Force}
- Write-Host -ForegroundColor Green "$computer - Done!"
- }
- else
- {
- #WinRM not enabled, delete file via UNC path
- $file = "\\$($computer)\c$\Windows\System32\FNTCACHE.DAT"
- Write-Host "WinRM is not enabled on $computer, proceeding..."
- Write-Host "$computer - Deleting files via UNC!"
- Remove-Item $file -force -recurse
- Write-Host -ForegroundColor Green "$computer - Done!"
- }
- }
- else
- {
- #PC was offline
- Write-Host -ForegroundColor Red "$computer - Offline!"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment