0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

IEのキャッシュフォルダをやっつける

Posted at

何をしたいか

IEのキャッシュが嫌い(様々な意味を含む)なので、リモートコンピュータのIEキャッシュフォルダを始末したい。

対象フォルダ

ユーザーフォルダ\AppData\Local\Microsoft\Windows\WebCache
ユーザーフォルダ\AppData\Local\Microsoft\Windows\INetCache
どっちもシステム属性・隠し属性を消してから手を出す。

書いたもの

削除だとキャッシュが多かった場合に思わぬ時間をとられるので、リネームにした。
実行する自分は相手を管理できるユーザーでないとならない。
また、当該PCにログオン中のユーザーには手を出せないのでエラーになる。

IECache_Clear_Remote.ps1
Write-Output "WebCache, INetCacheのリネーム"
$HostName = Read-Host "対象コンピュータ名を入力(止める場合はそのままEnter)"
if($null -eq $HostName){
  Write-Output "終了します"
  Start-Sleep -s 1
  exit
}else{
  Write-Output "${Hostname}のIEキャッシュフォルダをリネーム"
}

$RenameTime = get-date -Format yyyyMMddThhmmss

(Get-ChildItem -path "\\${HostName}\c$\Users" -Exclude Public).Name |
ForEach-Object{
  $WebCachePath = "\\${HostName}\c$\Users\${_}\AppData\Local\Microsoft\Windows\WebCache"
  $INetCachePath = "\\${HostName}\c$\Users\${_}\AppData\Local\Microsoft\Windows\INetCache"

  Write-Output "--------------------"
  Write-Output $_

  if(Test-Path $WebCachePath){
    Set-ItemProperty -LiteralPath $WebCachePath -Name Attributes -Value "Normal"
    (Rename-Item $WebCachePath "${WebCachePath}_${RenameTime}" -PassThru).Name
  }else{
    "${_} WebCacheフォルダ無し"
  }

  if(Test-Path $INetCachePath){
    Set-ItemProperty -LiteralPath $INetCachePath -Name Attributes -Value "Normal"
    (Rename-Item $INetCachePath "${INetCachePath}_${RenameTime}" -PassThru).Name
  }else{
    "${_} INetCacheフォルダ無し"
  }
}
Write-Output "--------------------"
Read-Host "Enterで閉じる..."

改良案

  • エラーハンドリング。
  • リネーム済みのフォルダを対象にして削除できるようにする。
  • 最初から削除も選べるようにする。
  • ログ残す。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?