Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Need Help with Powershell Script to Copy Folder

$
0
0

I've been testing this powershell script and everything seems to be working fine. The problem is that I would like to copy the folder N6200 with its content to C:\Temp and keep the same folder structure. The Remove-Item should delete the entire folder and its content after the software install. Is there a way to copy folders in Powershell?

$Servers = Get-Content '\\servera07111\FILES\computers.txt'
 
$FilePath = '\\servera07111\FILES\WIRELESS\N6200'
 
foreach ($Server in $Servers){
    if (Test-Path "\\$Server\c$\Temp"){
        Write-Host "Processing $Server..."
        # Copy update package to local folder on server
        Copy-Item $FilePath "\\$Server\c$\Temp"
        # Run command as SYSTEM via PsExec (-s switch)
        & C:\Windows\PSTools\PsExec -s \\$Server C:\Temp\N6200\DPInst32.exe /silent
        if ($LastExitCode -eq 3010) {
            $ConfirmReboot = $False
        } else {
            $ConfirmReboot = $True
        }
        # Delete local copy of update package
        Remove-Item "\\$Server\c$\Temp\N6200"
       
        Write-Host
    } else {
        Write-Host "Folder C:\Temp does not exist on the target server"
    }
}

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles