我正在尝试从网络计算机的C:\驱动器传输用户数据到本地计算机的C:\驱动器。因此,我需要排除所有系统文件夹和隐藏文件夹。
这是我的PowerShell脚本内容:
当我执行
看起来 robocopy 函数正在使用本地 C:\ 路径作为源。源应该是
例如。 如果这个文件夹在旧计算机上是
这是我的PowerShell脚本内容:
$asset = Read-Host "What is the Asset Number?"
$useraiu = Read-Host "What is the user's AIU?"
$source = "\\$asset\C$\"
$dest = "C:\Temp\Dest"
$excludedFolders = '_SMSTaskSequence','inetpub','Program Files','Program Files (x86)','Swsetup','Users','Windows','CCM','Notes'
$myFolders = Get-ChildItem -Path "\\$asset\C$\" -Directory | where { $_ -notin $excludedFolders }
$myFolders | foreach { robocopy $_ $dest /S /Z /MT /XJD /XA:SH /log+:"\\server\path\path\%asset%-to-%computername%-Transfer-Log.log" /NP /FP /V /TEE}
Read-Host "Press ENTER to quit"
当我执行
Write-Output $myFolders
时,它显示了我想要复制的正确目录。看起来 robocopy 函数正在使用本地 C:\ 路径作为源。源应该是
\\$asset\C$\
中列出的文件夹。例如。 如果这个文件夹在旧计算机上是
\\computername\C$\Userfolder-Pictures
,请使用 Robocopy 将该文件夹复制到本地计算机上的 C:\Userfolder-Pictures
运行脚本后,我从 Robocopy 得到了这个输出。 Log File : \\server\path\path\%asset%-to-%computername%-Transfer-Log.log
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Mon Jun 08 11:11:28 2015
Source : C:\WINDOWS\system32\Temp\
Dest : C:\Temp\Dest\
Files : *.*
Options : *.* /V /FP /TEE /S /COPY:DAT /Z /NP /XJD /XA:SH /MT:8 /R:1000000 /W:30
------------------------------------------------------------------------------
2015/06/08 11:11:28 ERROR 2 (0x00000002) Accessing Source Directory C:\WINDOWS\system32\Temp\
The system cannot find the file specified.
$asset
不是 null 或空的了吗? - Ansgar Wiechers