Reputation: 11
I have two directories A and B. A is having few *.dll files.B is also having *.dll files. Now I have to pick file from directory A and search in directory B, if found I will replace the file in B directory with the file in directory A. How I can write powershell script for this.
Upvotes: 0
Views: 172
Reputation:
IMO Replace / xcopy / robocopy will be faster or more efficient.
In powershell there are thousand ways to do it, here is one:
$DirA = "C:\Windows\System32\"
$DirB = "Q:\Test\2018\03\31\"
Get-ChildItem -Path $DirA -Filter *.dll |
Where-Object { Test-Path (Join-Path $DirB $_.Name) } |
Copy-Item -Destination (Join-Path $DirB $_.Name)
Upvotes: 1
Reputation: 5522
You don't need powershell for that.
robocopy src dest /XX
will suffice.
Upvotes: 0