2017-06-26 4 views
1

Ich benötige ein PS-Skript, um die Dokumente eines Benutzers an den Onedrive umzuleiten. Ich habe derzeit eine Batch-Datei, die ein Verzeichnis in OneDrive erstellen wird, aber ich brauche es, um den Standort tatsächlich umzuleiten, so dass es nicht 2 meine Dokumente gibt. Und würde PS bevorzugen. Hier ist mein Versuch PS Script ..Umleiten meines Dokumentordners zu Onedrive

$answer = Show-MsgBox -title "Changing the User Library Paths" -prompt "Do you want to change the user documents folder?" -BoxType YesNo -Icon Question 
if [$answer -eq "Yes"] 
    { 
    $MyDirs = Get-ChildItem "$HOME" -Name -Exclude "Links", "Searches" 
    if [$MyDirs] 
     { 
     $ShellFolder = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" 
     $UserShellFolder = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" 
     foreach [$MyDir in $MyDirs] 
      { 
      $RegName = Get-RegistryKeyPropertiesAndValues $ShellFolder |Where-Object {$_.Value -match "$MyDir"} |foreach {$_.property} 
      $answer = Show-MsgBox -title "Change $MyDir Folder" -prompt "Do you want to change the $Mydir folder?" -BoxType YesNo -Icon Question 
      if [$answer -eq "Yes"] 
       { 
       $inputbox = $null 
       $inputbox = Show-Inputbox -message "Enter the path of the $MyDir folder" -title "Entering path..." -default "D:\Users\$env:username\$MyDir" 
       if [$inputbox] 
        { 
        if [![Test-Path "D:\Users\$env:username\$MyDir"]] {New-Item "D:\Users\$env:username\$MyDir" -ItemType Directory -Force} 
        Set-ItemProperty -Path $ShellFolder -Name $RegName -Value $inputbox 
        Set-ItemProperty -Path $UserShellFolder -Name $RegName -Value $inputbox 
        Move-Item "$HOME\$MyDir\*" "D:\Users\$env:username\$MyDir" -Force 
        attrib +r "D:\Users\$env:username\$MyDir" 
        rd $HOME\$MyDir -recurse -Force 
        } 
       } 
      } 
     Show-MsgBox -title "Press OK to continue" -prompt "Folder redirection done!" -BoxType OkOnly -Icon Exclamation 
     cls 
     } 

Antwort

0

Sie können versuchen, diese Dokumente Lage und Bearbeiten für mehrere Ordner sowieso

Add-Type -AssemblyName System.Windows.Forms  
Add-Type -AssemblyName Microsoft.VisualBasic 

$answer =[System.Windows.Forms.MessageBox]::Show("Changing the User Library Paths","Do you want to change the user documents folder?" ,"YesNo","Question") 
if ($answer -eq "Yes") 
    { 
    #read your registery location documents C:\user\someone\documents 
    $RegPersonal = Get-ItemProperty -Path "HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -name "Personal" -ErrorAction SilentlyContinue 
    $RegPersonal.personal = $RegPersonal.personal.trim().ToLower() 

    #ansver your Documents Current Location 
    $answer =[System.Windows.Forms.MessageBox]::Show("Current Location is "+$RegPersonal.personal ,"Do you want to change the user documents folder?" ,"YesNo","Question") 
    } 

    #input new directory 
    if ($answer -eq "Yes") 

     { 
      $inputbox = $null 
      $inputbox = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the new path " +$RegPersonal.personal+ "folder", "Entering path... C:\Users\"+$env:username+"\"+$RegPersonal) 
     } 
      if ($answer -eq "No"){ 
      [void][System.Windows.Forms.MessageBox]::Show("Canceled by the user")  
      exit 
      } 

     #change new directory location register 
     if ($inputbox) 
      { 
      Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' -name Personal "$inputbox" 

     }    

    [void][System.Windows.Forms.MessageBox]::Show("Press OK to continue You need restart your Pc","Folder redirection done!",[Windows.Forms.MessageBoxButtons]::"OK",[Windows.Forms.MessageBoxIcon]::"Exclamation") 
+0

Gibt es zu ändern% Userprofile% hinzuzufügen zu Autoroute? –

+0

Oder verwenden Sie dies, aber fügen Sie zusätzlich Favoriten und Bilder hinzu? –

+0

Sie können einen Ordner Favoriten Bilder im Skript, eins nach dem anderen –