用户配置文件 Robocopy 备份

Userprofile Robocopy Backup

您好,我需要备份多台 PC 的用户配置文件,我可以使用一些全局命令(例如 %Userprofile%)来备份已登录的用户代码吗?另外,为什么我的脚本没有正确备份我告诉他的文件夹。输出目前不可访问,它只是说您需要更多权限才能打开这些文件夹。

$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

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 保护到特定用户。您可以通过 运行 具有管理员权限的脚本来解决这个问题。