Workspace-Guru

remove-vhd.ps1

Aug 18th, 2018
4,536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## USER VARIABLES
  2.  
  3. $vhdSharePath = "\\DOMAIN.LOCAL\dfsroot$\ostvhd" ## Path To OST Files
  4.  
  5. ## GLOBAL VARIABLES Start ##
  6. $userName = $env:USERNAME
  7. $userDomain = $env:USERDOMAIN
  8. $secUser = New-Object System.Security.Principal.NTAccount($userName)
  9. $userSID = $secUser.Translate([System.Security.Principal.SecurityIdentifier])
  10. $vhdFileName = $userName + "_EMCache.vhd"
  11. $vhdUserDirectoryName = $userName + "_" + $userSID
  12. $vhdDirectoryPath = $vhdSharePath + "\" + $vhdUserDirectoryName
  13. $vhdPath = $vhdDirectoryPath + "\" + $vhdFileName
  14. $workingDir = $env:USERPROFILE + "\AppData\Local\Temp\VHDCache"
  15. $filesystemlabel = $userName + "_EMcache"
  16. $outlookDir = $env:USERPROFILE + "\AppData\Local\Microsoft\Outlook"
  17.  
  18. ## GLOBAL VARIABLES End ##
  19.  
  20. ## UNMOUNT Start ##
  21. $mountPath = Join-Path -Path $workingDir -ChildPath VHD
  22. mountvol.exe $mountPath /d
  23. Remove-Item -Path "$workingDir" -Force -Recurse
  24.  
  25.  
  26. $cmd = @"
  27. Select vdisk file=$vhdPath
  28. detach vdisk
  29. exit
  30. "@
  31.  
  32. $cmd | diskpart | Out-Null
  33.  
  34. cmd.exe /C rd $outlookDir
  35.  
  36. ## UNMOUNT End ##
Advertisement
Add Comment
Please, Sign In to add comment