2017-05-12 4 views
1

안녕하세요 여러 PC의 userprofile을 백업해야합니다. 로그인 한 사용자를 백업하기 위해 % Userprofile %과 같은 전역 명령을 사용할 수 있습니까? 또한 내 스크립트가 내가 말한 폴더를 제대로 백업하지 않는 이유는 무엇입니까? 출력물은 현재 액세스 할 수 없으며이 폴더를 여는 데 더 많은 권한이 필요하다고합니다.Userprofile Robocopy Backup

$Destination=Read-Host "Please type the path directory you want to copy the backup files" #destination 
$Folder=Read-Host "Please type the root name folder" #name of backup folder 
$validation=Test-Path $Destination #validate the destination if it has the privileges 

New-PSDrive -Name "Backup" -PSProvider FileSystem -Root $Destination #temporary folder for the backup 

if ($validation -eq $True){ 

     Set-Location Backup: 
} 
else{ 

    Write-Host "Error!Run Script Again" 

    break 
} 

    robocopy "C:\Users\user\desktop" $Destination\$Folder *.* /mir /sec 
    robocopy "C:\Users\user\pictures" $Destination\$Folder *.* /mir /sec 
    robocopy "C:\Users\user\documents" $Destination\$Folder *.* /mir /sec 


Function Pause{ 

    Write-Host "Backup Sucessfull!!! `n" 

} 



Pause 

답변

1

PowerShell의 %Userprofile%의 동등한 $Env:UserProfile이다.

robocopy "$env:UserProfile\desktop" $Destination\$Folder *.* /mir /sec 
robocopy "$env:UserProfile\pictures" $Destination\$Folder *.* /mir /sec 
robocopy "$env:UserProfile\documents" $Destination\$Folder *.* /mir /sec 

스크립트가 권한에 대해 불만을 나타내고 있다면 사용자 폴더에 대한 권한이없는 계정을 통해 스크립트를 실행하고있는 것 같습니다. 사용자 폴더는 기본적으로 ACL에 의해 특정 사용자에게 보안됩니다. 관리자 권한으로 스크립트를 실행하면이 문제를 해결할 수 있습니다.

+0

덕분에 나는 일을 생각하지만 출력 – Valentino

+0

보면 내가 지금 직면하고있어 문제는 다음과 같습니다이다 : – Valentino

+0

http://imgur.com/a/5AZNa 난 당신이 날 도울 수 있기를 바랍니다 – Valentino