Powershell script not working properly

Hi Team I have powershell script that renames an existing file to a new file with appending sysdate, I am using the following script for this, this is called as part of another batch file, the file renaming is working properly but the sysdate is not appending properly for example today is 16th october but the file is renamed with 14th ocotober

function RenameFile
$source_file_name = get-ChildItem $source_dir -recurse | where {$_.name -like $source_file.replace("<date>",$source_filedate)} | select -exp name
if ([string]::IsNullOrEmpty($source_file_name))
throw 'File Missing: ' + $source_file

$source_file = $source_dir + $source_file_name
$file = Get-Item $source_file

$a = Get-Date -format ddMMyyyy
$target_file = $target_dir + $target_suffix+"_"+"$a"+$target_prefix
Copy-Item $source_file $target_file

$source_directory = "E:\CSBE\output_files\DUEDIL\BE\FTP\"
$target_directory = "E:\CSBE\output_files\DUEDIL\BE\FTP\SP_NEGINFO"

Remove-Item "E:\CSBE\output_files\DUEDIL\BE\FTP\SP_NEGINFO\temp\*" -Force -Recurse

$todays_date = Get-Date -format "yyyyMMdd"
RenameFile -source_dir $source_directory -source_file BE_NEGATIVE_INFORMATION_<date>_D.dsv -source_filedate $todays_date -target_dir $target_directory INSOLVENCY_BE -target_prefix.dsv

$target_directory_temp = "E:\CSBE\output_files\DUEDIL\BE\FTP\SP_NEGINFO\temp\"
RenameFile -source_dir $source_directory -source_file BE_NEGATIVE_INFORMATION_<date>_D.dsv -source_filedate $todays_date -target_dir $target_directory_temp INSOLVENCY_BE -target_prefix.dsv

cd "E:\CSBE\output_files\DUEDIL\BE\FTP\SP_NEGINFO\temp\"

dir "*.dsv" | ForEach-Object { & "\\Csgimp19\csbe2\bin\7Z.exe" a -tzip ($_.BaseName+".zip") $_.Name }

I don’t see anything odd there, add verbose statements and run it again with -Verbose.

Thank you.

I don’t see any obvious flaws so I would look at a few basic items:

  1. Is the system date on the server running the script correct?
  2. How long was this running? (is it possible the script has been running since 10/14? )
  3. Has it ever worked properly?
  4. If you run it manually does it work?