PowerShell script doesn't copy contents in specified folder RRS feed

  • Question

  • I have a script that should copy over a folder, and all of its contents, from computer A to computer B. If the folder exists on computer B, it should overwrite the folder. Right now when the script runs, it verifies the path (no issues), deletes the existing folder (no issues), then copies the folder from computer A, but the folder is empty on computer B. I have verified that there is content in the folder before it copies. Is there something I am missing? Any help would be greatly appreciated

    # PowerShell Read-Host Input Box
    #Ask for Admin Credentials
    if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
    #Get and set varible names
    $ComputerName1 = Read-Host "What is the name of your computer?"
    $ComputerName2 = Read-Host "What is the name of the computer you are fixing?"
    #If folder exists, overwrite it
    If(test-path "\\$ComputerName2\c$\ProgramData\Micro Focus"){Remove-item "\\$ComputerName2\c$\ProgramData\Micro Focus"}
    #Copy from one computer to the next
    Copy-Item -Path "\\$ComputerName1\c$\ProgramData\Micro Focus" "\\$ComputerName2\c$\ProgramData\Micro Focus"
    #Delete folder from all users
    Remove-Item -path "\\$ComputerName2\c$\Users\*\AppData\Roaming\Micro Focus"
    #Disply message complete
    Read-Host -Prompt "Micro Focus Fix complete, press Enter to Exit"

    • Moved by Bill_Stewart Wednesday, November 29, 2017 6:38 PM This is not "fix/debug/rewrite my script for me" forum
    Monday, October 16, 2017 1:39 PM

All replies

  • The correct command looks like this:

    copy-item c:\test1\* c:\testxx -Force

    It will create the folder and copy all files and subdirs  to the target.


    Monday, October 16, 2017 1:59 PM