Snippet Name: Extract_Package_Names_Script
Tags:
Created Date: 2025-06-16 13:12:39
Last Modified Date: 2025-05-31 10:31:49
Dependencies:
DBA Notes:
Sample Output:
Title: Extract Package Names Script
Author: user
i have a folder full of *.dtsx files in "C:\_Data\Lowell\CompPlans.SSIS\" , i know there are tags like <PackageName>WD_EMPLOYEES.dtsx</PackageName>, which are artifacts of Execute Package Tasks. i need the output of the current file name, plush all strings that were between the multiple <PackageName> tags
Author: ChatGPT
User is working with *.dtsx files in "C:\_Data\Lowell\CompPlans.SSIS\" that contain tags like `<PackageName>WD_EMPLOYEES.dtsx</PackageName>`, which are artifacts of Execute Package Tasks. They want to extract the current file name and all strings between the multiple `<PackageName>` tags.
Author: tool
Model set context updated.
Author: ChatGPT
You can use PowerShell to process these `.dtsx` files and extract the current file name along with all the strings between the `<PackageName>` tags. Here's a script that will do that:
```powershell
# Set the folder path
$folderPath = "C:\_Data\Lowell\CompPlans.SSIS\"
# Get all *.dtsx files in the folder
$dtsxFiles = Get-ChildItem -Path $folderPath -Filter *.dtsx
# Loop through each file
foreach ($file in $dtsxFiles) {
# Get the file name
$fileName = $file.Name
# Read the file content
$content = Get-Content -Path $file.FullName -Raw
# Use regex to extract all <PackageName> tags
$packageNames = &#91;regex]::Matches($content, "<PackageName>(.*?)</PackageName>").Value
# Output the file name and the package names
Write-Output "File: $fileName"
foreach ($packageName in $packageNames) {
Write-Output $packageName
}
}
```
This script will:
1. Loop through all `.dtsx` files in the specified folder.
2. Extract strings between the `<PackageName>` tags.
3. Output the current file name and the extracted strings.
You can redirect the output to a file if needed:
```powershell
# Redirect output to a text file
$outputFile = "C:\_Data\Lowell\PackageNamesOutput.txt"
foreach ($file in $dtsxFiles) {
$fileName = $file.Name
$content = Get-Content -Path $file.FullName -Raw
$packageNames = &#91;regex]::Matches($content, "<PackageName>(.*?)</PackageName>").Value
Add-Content -Path $outputFile -Value "File: $fileName"
foreach ($packageName in $packageNames) {
Add-Content -Path $outputFile -Value $packageName
}
}
```
This version saves the results in a text file.