Powershell 用户配置文件Robocopy备份

Powershell 用户配置文件Robocopy备份,powershell,backup,robocopy,Powershell,Backup,Robocopy,您好,我需要备份多台电脑的userprofile,我可以使用一些全局命令,如%userprofile%,为我的代码备份登录的用户。还有为什么我的脚本没有正确备份我告诉他的文件夹。输出当前不可访问,只是表示您需要更多权限才能打开这些文件夹 $Destination=Read-Host "Please type the path directory you want to copy the backup files" #destination $Folder=Read-Host "Please ty

您好,我需要备份多台电脑的userprofile,我可以使用一些全局命令,如%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保护到特定用户。您可能可以通过使用管理员权限运行脚本来解决此问题。

谢谢,我想它是有效的,但我现在面临的问题是,当我查看输出时,它看起来是这样的:我不清楚您的问题(是文档被复制了吗?)。我认为您可能应该打开一个新的问题来解释您的问题以及您使用的代码/输入。