[Solved] Using Powershell to copy file from network drive to local drive


Your example is almost complete on its own. You can further your pipeline:

$UNC = '\\share'
$Path="C:\Temp"

Get-ChildItem -Path $UNC |
    Where-Object { $_.LastWriteTime -lt (Get-Date) } |
    ForEach-Object {
        Copy-Item -Path $_.FullName -Destination $Path
    }

Although, an improvement:

$Path="C:\Temp"
$UNC = Get-ChildItem -Path '\\share' -File
$Local = Get-ChildItem -Path $Path -File

ForEach ($File in $UNC)
{
    $Compare = $Local | Where-Object { $_.Name -eq $File.Name }
    If ($Compare -and $Compare.LastWriteTime -gt $File.LastWriteTime)
    {
        Copy-Item -Path $File.FullName -Destination $Path -Force
    }
}

5

solved Using Powershell to copy file from network drive to local drive