Skip to content

Instantly share code, notes, and snippets.

@rolambert
Created July 15, 2020 15:15
Show Gist options
  • Save rolambert/538c8c44a5475f26168c8465cfd1b929 to your computer and use it in GitHub Desktop.
Save rolambert/538c8c44a5475f26168c8465cfd1b929 to your computer and use it in GitHub Desktop.
the script takes ownership of client side cache content on windows 7
function takeownershipandmovecsc{
param(
[String]$username, #$env:username
[string]$homeshare,
[String]$homea, # $home
[string]$systemroot, # $env:systemroot
[String]$SysDrive #$env:SystemDrive
)
function setregdocumentfolder($val){
if(Test-Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'){
Set-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' -Name 'My Music' -value $val
Set-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' -Name 'My Video' -value $val
Set-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' -Name 'My Pictures' -value $val
Set-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' -Name 'Personal' -value $val
}
}
Function Test-IsAdmin
{
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal $identity
$principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
$cscshare= $homeshare
$cscshare=$cscshare.Substring(1,$cscshare.length-1)
$cscsharecut=$cscshare.Substring(0,$cscshare.length-1)+"```$"
Takeown /f "$systemroot\csc" /r /d y
$allcachefiles = "$systemroot\csc\v2.0.6\namespace\File086\*" | gci -Recurse
$grantstring = $username +":f"
$allcachefiles | %{ Icacls $_.FullName /grant $grantstring /inheritance:r}
#create directory
mkdir $home\Documents | out-null
copy "$systemroot\csc\v2.0.6\namespace$cscshare\My Documents\*" -Destination "$home\Documents" -Recurse
Move "$SysDrive\Users\$username\Documents\My Pictures" -Destination "$home"
Move "$home\Documents\My Music" -Destination "$home\"
Move "$home\Documents\My Videos" -Destination "$home\"
#remove
#rm C:\Users\rolambert\documents
$val = "$home\Documents"
setregdocumentfolder($val)
}
takeownershipandmovecsc -username rolambert -homeshare \\file086\a09$ -home c:\users\rolambert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment