如何编辑此代码以复制所有子目录及其内容,然后将其粘贴到远程工作站?
此代码的目的是远程卸载 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 \$computerc$Transfer2007 -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
foreach ($item in $items)
{
Write-Host "Copying $Item over to $Computerc$Transfer2007" -ForegroundColor Yellow
Copy-Item -Path $item -Destination \$ComputerC$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"目录的内容被粘贴到远程工作站中。我需要粘贴所有子目录及其内容。
尝试Get-Item -Recursive
还要看看powershell workflow
它允许您一次安装32个会话
Copy-Item
需要添加-Recurse
参数,因此Copy-Item
行应为:
Copy-Item -Path $item -Destination \$ComputerC$Transfer2007 -Recurse -Force