title: Force overwrite files and its subdirectories from UNCPath using Powershell?
body: <p>As part of the Group Policy to force daily update the custom application, I need to check the .NET Framework to be more than 3.5 and above.</p>
  <p><strong>Computer Configuration | Policies | Windows Settings | Scripts| Startup</strong>
  For this GPO, Script order: Windows PowerShell scripts will run first
  Update-Files-FromServer.ps1</p>
  <p>So far no files copied and no error logged shown?</p>
  <p>The below code is not working or copying the directories of files and its subdir from the fileserver to the workstation:</p>
  <pre><code>$mailArgs = @{
      From = &quot;$env:USERNAME@$env:userdnsdomain&quot;
      To = 'Helpdesk@domain.com'
      Subject = &quot;Unable to update Custom Application files from $env:computername.$env:USERDNSDOMAIN&quot;
      SmtpServer = 'SMTP.domain.com'
      BodyAsHtml = $true
  }
  
  $computer = $ENV:COMPUTERNAME
  $source = &quot;\\FILESVR01\IT\Custom Application\Modules\*&quot;
  $destination = &quot;C$\Program Files (x86)\Custom Application\Modules\&quot;
  $RunTimeVersion = (Get-ItemProperty &quot;HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client&quot; -Name Version).Version
  
  If ((Test-Path -Path &quot;\\$($computer)\$($destination)&quot;) -and ($RunTimeVersion -gt 3.5))
  {
      Try
      {
          # The -Verbose in the Copy-Item cmdlet will show each file that's copied.
          Copy-Item -Path $source -Destination &quot;\\$($computer)\$($destination)&quot; -Recurse -Force -Verbose -ErrorAction Stop
          Write-Host &quot;Sucessfully copied on $($computer)&quot; -BackgroundColor Green
      }
      Catch
      {
          Write-Host $_.Exception.Message -ForegroundColor Red
      }
  }
  Else
  {
      Write-Host &quot;Target folder '\\$($computer)\$($destination)' not found or not accessible!&quot; -ForegroundColor Red
      Send-MailMessage @mailArgs -Priority High
  }
  </code></pre>