PowerShell cmd是否复制和粘贴所有子目录及其内容?

PowerShell cmd是否复制和粘贴所有子目录及其内容?,powershell,active-directory,ms-office,Powershell,Active Directory,Ms Office,如何编辑此代码以复制所有子目录及其内容,然后将其粘贴到远程工作站 此代码用于远程卸载MS Office 2007。我使用相同的代码安装新版本 $Computers = (Get-ADComputer -Filter * -SearchBase "OU=X,DC=Y,DC=Z").Name ForEach ($Computer in $Computers) { Write-Host "Working on $Computer" -ForegroundColor White Write-Host "

如何编辑此代码以复制所有子目录及其内容,然后将其粘贴到远程工作站

此代码用于远程卸载MS Office 2007。我使用相同的代码安装新版本

$Computers = (Get-ADComputer -Filter * -SearchBase "OU=X,DC=Y,DC=Z").Name
ForEach ($Computer in $Computers)
{
Write-Host "Working on $Computer" -ForegroundColor White
Write-Host "Testing access to $Computer" -ForegroundColor White
$HostUp = Test-Connection -ComputerName $Computer -BufferSize 12 -Count 1
If (!($HostUp))
{
Write-Warning -Message "Remote Host is not accessible!" }
Else
{
Write-Host "Success!" -ForegroundColor Green
$items = Get-Item -Path C:\Transfer2007\*
Write-Host "Creating Transfer folder on $Computer" -ForegroundColor Yellow
New-Item -Path \\$computer\c$\Transfer2007 -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
foreach ($item in $items)
{
Write-Host "Copying $Item over to $Computer\c$\Transfer2007\" -ForegroundColor Yellow
Copy-Item -Path $item -Destination \\$Computer\C$\Transfer2007\ -Force
}
Write-Host "Starting setup on $Computer" -ForegroundColor White
Invoke-Command -ScriptBlock { set-location "C:\Transfer2007\"; .\SETUP.exe /uninstall ProPlus /config \UninstallConfig.xml } -ComputerName $Computer -AsJob
}
}
Get-Job | Format-Table
pause

使用此代码,只有“Transfer2007”目录的内容才会粘贴到远程工作站中。我需要粘贴所有子目录及其内容。

Copy Item
需要添加
-Recurse
参数,因此您的
Copy Item
行应该是:

Copy-Item -Path $item -Destination \\$Computer\C$\Transfer2007\ -Recurse -Force
试一试
获取项目-递归

还可以查看
powershell工作流
它允许您一次安装32个会话