The following script filters out filenames in powershell.

The filenames all have a known pattern of ServerName-DatabaseName-FilterName.sql

# Suppose these are your initial variables
$publication_files = @("Server1-Database1-Publication1.sql", "Server2-Database2-Publication2.sql", "Server3-Database3-Publication3.sql")
$publication = "Publication1"

# Filter the publication_files array
$filtered_publications = $publication_files | Where-Object {
    # Split each file name by '-' and take the third part (Publication name)
    $file_publication = ($_.Split('-'))[2]

    # Remove the file extension '.sql' from the Publication name
    $file_publication = $file_publication.Replace(".sql", "")

    # Check if the Publication name ends with the value of $publication
    $file_publication -eq $publication
}

# Print the filtered publications
$filtered_publications

By Rudy