Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <# if your users are not admins then you will have to grant them the "Create symbolic links" right through gpo
- Computer Configuration\Policies\Windows Settings\Security Settings\Local Policies\User Rights Assignment
- #>
- <# tests if a folder is a reparse point called from create-vdipaths function #>
- function Test-ReparsePoint([string]$rpath) {
- $file = Get-Item $rpath -Force -ea 0
- return [bool]($file.Attributes -band [IO.FileAttributes]::ReparsePoint)
- }
- <# this function does pretty much everything #>
- function create-vdipaths([string]$syslocal,[string]$syshome,[string]$rl) {
- $command = "cmd /c mklink /d" # mklink.exe - base command to create the junction
- if ($rl -eq "local") { # check to see if it is a local path or roaming
- $syslp = Join-Path $env:localappdata $syslocal # if local joins %localappdata% to the root path from the csv file
- } elseif ($rl -eq "roam") { # if roaming joins %appdata% (roaming) to the root path
- $syslp = Join-Path $env:appdata $syslocal
- }
- $sysh = Join-Path $env:homeshare $syshome # sets the path to copy to
- if (!(Test-Path $sysh)) { # if $sysh path does not exist creates the folder
- md $sysh | Out-Null
- }
- if (Test-Path $syslp) { # if the local path exists...
- $testreparse = Test-ReparsePoint -rpath $syslp # calls test-reparsepoint function - returns True or False
- if ($testreparse -eq $false) { # if the path is NOT a junction point
- if ($syslp -like "*2.0") { # this is my specific check for the %localappdata%\apps\2.0 directory
- & Robocopy.exe $syslp $sysh /e /MOVE | Out-Null # moves the existing data to the user's homeshare directory
- } else {
- ri $syslp -Recurse -Force # in my case I don't care if someone installed chrome or firefox to their profile... delete
- }
- Invoke-Expression "$command `"$syslp`" `"$sysh`"" | Out-Null # creates the junction point
- }
- } else { # if the local path does not exist...
- md $syslp | Out-Null # makes the directory (in case it is not in the root ie: Apps\2.0)
- ri $syslp -Recurse -Force # deletes the directory (in the case of Apps\2.0 it would leave Apps)
- Invoke-Expression "$command `"$syslp`" `"$sysh`"" | Out-Null # creates the junction point
- }
- }
- # Where the script actually starts!!
- Set-Location C:\ # This way there are no error messages from cmd about running from a remote location
- Import-Csv \\server\share\csvfile.csv | %{ # path to your CSV file - explanation below
- create-vdipaths -syslocal $_.localpath -syshome $_.homepath -rl $_.lorr # calls the create-vdipaths function above
- }
- <# CSV file should have headers "localpath" "homepath" and "LorR"
- Here is an example:
- LocalPath,HomePath,LorR
- Google,VDIPaths\GoogleChrome\Googleroam,Roam
- Google,VDIPaths\GoogleChrome\Googlelocal,Local
- Mozilla,VDIPaths\MozillaFirefox\Firefoxroam,Roam
- Mozilla,VDIPaths\MozillaFirefox\Firefoxlocal,Local
- Apps\2.0,VDIPaths\localapps\Apps\2.0,Local
- Take the first actual line (after the headers)
- Google,VDIPaths\GoogleChrome\Googleroam,Roam
- Google is in the root of %appdata%
- I want to create a path in $env:homeshare\VDIPaths\GoogleChrome\Googleroam
- 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)
- #>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement