So add those five fixed digits to the file mask:
"get -delete 12345*.xml newname" `
"get -delete 12345*.xml newname" `
get
command:
"get -delete *.xml newname" `
"get -delete *.xml" `
$folder_path = "SMB share"
$old_name_prefix = "XXXX"
$new_name_prefix = "XXX"
$today_date = Get-Date -Format "yyyyMMdd"
Set-Location -Path $folder_path
Get-ChildItem -Path . -Filter "$old_name_prefix*" | ForEach-Object {
$new_filename = "$new_name_prefix" + "." + $today_date + $_.Extension
Rename-Item -Path $_.FullName -NewName $new_filename
Write-Output "File '$($_.Name)' has been renamed to '$new_filename'"
return
}
Write-Output "No file found starting with '$old_name_prefix'"
$PSNativeCommandArgumentPassing = "Legacy"
& "C:\Program Files (x86)\WinSCP\WinSCP.com" `
/log="C:\Program Files (x86)\WinSCP\script\Log\WinSCP.log" /ini=nul `
/command `
"open sftp://XXXXXXXXXXXX" `
"cd /Folder/foldername" `
"lcd \\SMB-share" `
"get 12345678" `
"exit"
$winscpResult = $LastExitCode
if ($winscpResult -eq 0)
{
Write-Host "Success"
}
else
{
Write-Host "Error"
}
exit $winscpResult