You can do it this way:
$LatestFullBackupFile = Get-ChildItem -Path $BackupDir -Filter $SourceDbbkp*.bak |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1 -Expand Name
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am writing a powershell script read last column value into a variable and get numeric value component
this powershell returns as follows
$LatestFullBackupFile = Get-ChildItem -Path $BackupDir -Filter $SourceDbbkp*.bak | Sort-Object LastWriteTime -Descending | Select-Object -First 1
Write-Output $LatestFullBackupFile
++++++++++++++++++++
output:
Mode LastWriteTime Length Name
-a---- 21/04/2023 3:56 AM 565042614272 PRODCRM_backup_202304210300.bak so how do i delimiter given output to get last column PRODCRM_backup_202304210300.bak" value? any idea would be highly appreciate
Answer accepted by question author
You can do it this way:
$LatestFullBackupFile = Get-ChildItem -Path $BackupDir -Filter $SourceDbbkp*.bak |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1 -Expand Name
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more