您好我需要备份多台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
答案 0 :(得分: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
如果您的脚本抱怨权限,则可能是您通过无权访问users文件夹的帐户运行该脚本。默认情况下,用户文件夹由ACL保护到特定用户。您可以通过使用管理员权限运行脚本来解决此问题。