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 ( [string]$source_dir, [string]$source_file, [string]$source_filedate, [string]$target_dir, [string]$target_prefix, [string]$target_suffix ) { $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 } else { $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 }