Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <# if your users are not admins then you will have to grant them the "Create symbolic links" right through gpo
  2. Computer Configuration\Policies\Windows Settings\Security Settings\Local Policies\User Rights Assignment
  3. #>
  4.  
  5. <# tests if a folder is a reparse point called from create-vdipaths function #>
  6. function Test-ReparsePoint([string]$rpath) {
  7.   $file = Get-Item $rpath -Force -ea 0
  8.   return [bool]($file.Attributes -band [IO.FileAttributes]::ReparsePoint)
  9. }
  10.  
  11. <# this function does pretty much everything #>
  12. function create-vdipaths([string]$syslocal,[string]$syshome,[string]$rl) {
  13. $command = "cmd /c mklink /d" # mklink.exe - base command to create the junction
  14. if ($rl -eq "local") { # check to see if it is a local path or roaming
  15. $syslp = Join-Path $env:localappdata $syslocal # if local joins %localappdata% to the root path from the csv file
  16. } elseif ($rl -eq "roam") { # if roaming joins %appdata% (roaming) to the root path
  17. $syslp = Join-Path $env:appdata $syslocal
  18. }
  19. $sysh = Join-Path $env:homeshare $syshome # sets the path to copy to
  20. if (!(Test-Path $sysh)) { # if $sysh path does not exist creates the folder
  21. md $sysh | Out-Null
  22. }
  23. if (Test-Path $syslp) { # if the local path exists...
  24. $testreparse = Test-ReparsePoint -rpath $syslp # calls test-reparsepoint function - returns True or False
  25. if ($testreparse -eq $false) { # if the path is NOT a junction point
  26. if ($syslp -like "*2.0") { # this is my specific check for the %localappdata%\apps\2.0 directory
  27. & Robocopy.exe $syslp $sysh /e /MOVE | Out-Null # moves the existing data to the user's homeshare directory
  28. } else {
  29. ri $syslp -Recurse -Force # in my case I don't care if someone installed chrome or firefox to their profile... delete
  30. }
  31. Invoke-Expression "$command `"$syslp`" `"$sysh`"" | Out-Null # creates the junction point
  32. }
  33. } else { # if the local path does not exist...
  34. md $syslp | Out-Null # makes the directory (in case it is not in the root ie: Apps\2.0)
  35. ri $syslp -Recurse -Force # deletes the directory (in the case of Apps\2.0 it would leave Apps)
  36. Invoke-Expression "$command `"$syslp`" `"$sysh`"" | Out-Null # creates the junction point
  37. }
  38. }
  39.  
  40. # Where the script actually starts!!
  41. Set-Location C:\ # This way there are no error messages from cmd about running from a remote location
  42. Import-Csv \\server\share\csvfile.csv | %{ # path to your CSV file - explanation below
  43. create-vdipaths -syslocal $_.localpath -syshome $_.homepath -rl $_.lorr # calls the create-vdipaths function above
  44. }
  45.  
  46. <# CSV file should have headers "localpath" "homepath" and "LorR"
  47. Here is an example:
  48. LocalPath,HomePath,LorR
  49. Google,VDIPaths\GoogleChrome\Googleroam,Roam
  50. Google,VDIPaths\GoogleChrome\Googlelocal,Local
  51. Mozilla,VDIPaths\MozillaFirefox\Firefoxroam,Roam
  52. Mozilla,VDIPaths\MozillaFirefox\Firefoxlocal,Local
  53. Apps\2.0,VDIPaths\localapps\Apps\2.0,Local
  54.  
  55. Take the first actual line (after the headers)
  56. Google,VDIPaths\GoogleChrome\Googleroam,Roam
  57. Google is in the root of %appdata%
  58. I want to create a path in $env:homeshare\VDIPaths\GoogleChrome\Googleroam
  59. Roam tells the script it is the roaming path (guess I could have just looked for roam in the path, but I wanted to be able to add paths in later that might not be in appdata)
  60. #>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement