Skip to content

Instantly share code, notes, and snippets.

@ivanbuzyka
Created August 23, 2021 15:36
Show Gist options
  • Save ivanbuzyka/8ac2df1406717360c330fb9cde77ec31 to your computer and use it in GitHub Desktop.
Save ivanbuzyka/8ac2df1406717360c330fb9cde77ec31 to your computer and use it in GitHub Desktop.
Powershell script for looking through CSV using regular expression and outputting matching string. Can be used in Content Hub target job export to analyze imageMagick failures
$csvFile = Get-Item "C:\path-to-csv-file.csv"
$stateDescriptions = Import-Csv $csvFile -Delimiter ';' | Select-Object Target.StateDescription
$result1 = @()
foreach($desc in $stateDescriptions)
{
# searching for filename with extension here (example pattern match /123testfile.tif:)
$desc -match "\/(?<filename>[^\/]*\.\w+):" #"\/\d{6}_.+\.[a-z0-9]+:"
if($Matches.Count -gt 0)
{
Write-Host $Matches.filename
$result1 += [PSCustomObject]@{
Name = $Matches.filename
}
}
}
$result1 | Select-Object Name -Unique | Export-Csv -NoTypeInformation -Path .\FileNames.csv -Delimiter ';'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment