Welcome › Forums › General PowerShell Q&A › Powershell script not working properly
- This topic has 2 replies, 3 voices, and was last updated 1 month, 3 weeks ago by
Participant.
Viewing 2 reply threads
-
AuthorPosts
-
-
October 16, 2019 at 9:38 am #183165
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("
",$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_ _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_ _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 } -
October 16, 2019 at 11:11 am #183201
I don't see anything odd there, add verbose statements and run it again with -Verbose.
Thank you.
-
October 16, 2019 at 3:16 pm #183279
I don't see any obvious flaws so I would look at a few basic items:
- Is the system date on the server running the script correct?
- How long was this running? (is it possible the script has been running since 10/14? )
- Has it ever worked properly?
- If you run it manually does it work?
-
-
AuthorPosts
Viewing 2 reply threads
- You must be logged in to reply to this topic.