I changed to power shell. This is what I ended up with:
function SortPictures
{
Set-Location \\NAS\Record
Set-Location \\Router\hdd1
#rename files
$files = get-childitem -path $folder -recurse -Include "*.jpeg", "*.jpg" | where { -not $_.PSIsContainer }
[datetime]$dirDate = New-Object DateTime...