我整理了一个Robocopy脚本来备份数据,但我遇到的问题是脚本正在读取父文件夹并尝试执行robocopy过滤器并输出错误。 我想要它做的是缩进一个并开始复制子文件夹并在那里使用过滤器。
文件结构用户\ tim jones,sam adams
我只想添加tim jones文件夹和添加了Robocopy过滤器的sam adams用户文件夹。欢迎任何帮助
$Comp = Read-Host 'Please enter a computer name or IP'
do{
If (Test-Connection $Comp -quiet -Count 1) {
Write-host 'The host responded' -ForegroundColor "yellow"
Read-Host 'Press any key to continue...' | Out-Null
$ping = "ture"
Clear-Host
Get-WmiObject -ComputerName $Comp -class Win32_NetworkLoginProfile | Select- Object Name,@{label='LastLogon';expression={$_.ConvertToDateTime($_.LastLogon)}}
New-Item -Path \\skyzone\t$\sky\ -ItemType directory
$SourcePath = "\\$Comp\C$\Users\";
$TargetPath = "\\skyzone\t$\sky";
#Users libraries
$PicturesLibrary = ("\Pictures");
$Downloads = ("\Downloads");
$Favorites = ("\Favorites");
$Documents = ("\Documents");
$Desktop = ("\Desktop");
$Video = ("\Videos");
#User Outlook files and logs
$Outlook = ("\AppData\Local\Microsoft\Outlook")
$argsFromFolders = ("$SourcePath\$PicturesLibrary","$SourcePath\$Downloads","$SourcePath\$Favorites","$SourcePath\$Documents","$SourcePath\$Desktop","$SourcePath\$Video" ,"$SourcePath\$Outlook");
$argsToFolders = ("$TargetPath\Pictures","$TargetPath\Downloads","$TargetPath\Favorites","$TargetPath\Documents","$TargetPath\Desktop","$TargetPath\Videos","$TargetPath\Outlook");
For ($i=0; $i -lt $argsFromFolders.Length; $i++) {
Write-Host -ForegroundColor Green "Processing" $argsFromFolders[$i] "To" $argsToFolders[$i];
robocopy $argsFromFolders[$i] $argsToFolders[$i] *.* /MT:16 /XJ *.pst /R:3 /W:1 /NP /e /xf *.vmdk *.vmem *.iso *.exe *.ost desktop.ini /tee /Log+:
}
答案 0 :(得分:0)
您的问题不明确,样本不完整。您可以在此处引用永远不会创建且-m
- 来电的$user
。因此,我无法为您提供完整的解决方案。
在代码中查看此示例源路径:
robocopy
加入两个字符串的地方有太多的反斜杠。从变量中删除它们或使用$SourcePath = "\\localhost\C$\Users\";
$PicturesLibrary = ("\Pictures");
"$SourcePath\$PicturesLibrary"
#Output
\\localhost\C$\Users\\\Pictures
Join-Path
或者
$SourcePath = "\\localhost\C$\Users\"
$PicturesLibrary = "\Pictures"
Join-Path $SourcePath $PicturesLibrary
#Output
\\localhost\C$\Users\Pictures
缺少用户名。您需要在$SourcePath = "\\localhost\C$\Users"
$PicturesLibrary = "Pictures"
"$SourcePath\$PicturesLibrary"
#Output
\\localhost\C$\Users\Pictures
上使用Get-Childitem
来获取用户列表并循环显示这些用户。
样品:
$sourcePath
更新:尝试这样的事情(未经测试)。
$SourcePath = "\\localhost\C$\Users\"
Get-ChildItem -Path $SourcePath |
#Get folders only... And exlude public?
Where-Object { $_.PSIsContainer -and $_.Name -ne 'Public' } |
ForEach-Object {
#Code to run for each user-folder
$PicturesLibrary = ("Pictures")
Join-Path $_.FullName $PicturesLibrary
}
\\localhost\C$\Users\Default.migrated\Pictures
\\localhost\C$\Users\defaultuser0\Pictures
\\localhost\C$\Users\frode\Pictures