Share via

Powershell read a variable value and sub-string

Ashwan 536 Reputation points
2023-04-21T05:24:07.39+00:00

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



Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author

Rich Matheisen 48,116 Reputation points
2023-04-21T15:30:01.1133333+00:00

You can do it this way:

$LatestFullBackupFile = Get-ChildItem -Path $BackupDir -Filter $SourceDbbkp*.bak | 
    Sort-Object LastWriteTime -Descending | 
        Select-Object -First 1 -Expand Name

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. Deleted

    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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.