title: Delete files and folders older than x days in remote windows server using windows powershell
body: <p>I am new to windows powershell. I have a script to identify the files and folders older than x files and delete it. but I need a script to check the same in remote windows server and do the same. Here is my code:</p>
  
  <pre><code>$Now = Get-Date
  $Days = "3"
  $TargetFolder = "D:\hudson_slave\workspace"
  $LastWrite = $Now.AddDays(-$Days)
  $Files = Get-Childitem $TargetFolder -Include $Extension -Recurse | Where {$_.LastWriteTime -le "$LastWrite"} 
  
   foreach ($File in $Files)
       {
       if ($File -ne $NULL)
           {
           write-host "Deleting File $File" -ForegroundColor "DarkRed"
             Remove-Item $File.FullName | out-null
           }
       else
           {
           Write-Host "No more files to delete!" -foregroundcolor "Green"
           }
       }
  </code></pre>
  
  <p>Could any one please help me to delete the 3 days older files and folders in remote server (using IP) </p>