# Author: Scott Sutherland, NetSPI (@_nullbind / nullbind) function Get-SSISCredentials { param ( [Parameter(Mandatory = $true)] [string]$FilePath ) # Check if the file exists if (-not (Test-Path -Path $FilePath)) { Write-Error "File not found: $FilePath" return } # Load the XML content from the file [xml]$xmlContent = [xml](Get-Content -Path $FilePath -Raw) # Ensure the XML content is valid if (-not $xmlContent) { Write-Error "Failed to load XML content." return } # Define the namespace manager and add the DTS namespace $namespaceManager = New-Object System.Xml.XmlNamespaceManager($xmlContent.NameTable) $namespaceManager.AddNamespace("DTS", "http://schemas.microsoft.com/sqlserver/Dts") # Prepare an array to hold extracted credentials $credentials = @() # Extract OLEDB connection credentials $dbConnections = $xmlContent.SelectNodes("//DTS:ConnectionManager[@DTS:CreationName='OLEDB']/DTS:Properties", $namespaceManager) foreach ($dbConnection in $dbConnections) { $connString = $dbConnection.SelectSingleNode("DTS:Property[@DTS:Name='ConnectionString']", $namespaceManager).'#text' if ($connString -match "Data Source=([^;]+);.*User ID=([^;]+);.*Password=([^;]+);") { $credentials += [pscustomobject]@{ ConnectionType = "Database" Server = $matches[1] Port = "N/A" # OLEDB typically does not specify a port Username = $matches[2] Password = $matches[3] } } } # Extract FTP connection credentials $ftpConnections = $xmlContent.SelectNodes("//DTS:ConnectionManager[@DTS:CreationName='FTP']/DTS:Properties", $namespaceManager) foreach ($ftpConnection in $ftpConnections) { $server = $ftpConnection.SelectSingleNode("DTS:Property[@DTS:Name='ServerName']", $namespaceManager).'#text' $port = $ftpConnection.SelectSingleNode("DTS:Property[@DTS:Name='ServerPort']", $namespaceManager).'#text' $username = $ftpConnection.SelectSingleNode("DTS:Property[@DTS:Name='ServerUserName']", $namespaceManager).'#text' $password = $ftpConnection.SelectSingleNode("DTS:Property[@DTS:Name='ServerPassword']", $namespaceManager).'#text' $credentials += [pscustomobject]@{ ConnectionType = "FTP" Server = $server Port = $port Username = $username Password = $password } } # Extract SMTP connection credentials $smtpConnections = $xmlContent.SelectNodes("//DTS:ConnectionManager[@DTS:CreationName='SMTP']/DTS:Properties", $namespaceManager) foreach ($smtpConnection in $smtpConnections) { $server = $smtpConnection.SelectSingleNode("DTS:Property[@DTS:Name='SmtpServer']", $namespaceManager).'#text' $port = $smtpConnection.SelectSingleNode("DTS:Property[@DTS:Name='Port']", $namespaceManager).'#text' $username = $smtpConnection.SelectSingleNode("DTS:Property[@DTS:Name='UserName']", $namespaceManager).'#text' $password = $smtpConnection.SelectSingleNode("DTS:Property[@DTS:Name='Password']", $namespaceManager).'#text' $credentials += [pscustomobject]@{ ConnectionType = "SMTP" Server = $server Port = $port Username = $username Password = $password } } # Return all credentials return $credentials } # Example usage: $results = Get-SSISCredentials -FilePath "c:\temp\configs\example.dtsx" $results | Format-Table -AutoSize <# example.dtsx - SQL Server ssis package file Data Source=dbserver1;Initial Catalog=Database1;User ID=dbuser1;Password=dbpassword1; Primary Database Connection True Data Source=dbserver2;Initial Catalog=Database2;User ID=dbuser2;Password=dbpassword2; Secondary Database Connection True ftpserver.com ftpuser ftppassword 21 60 True smtp.mailserver.com 25 smtpuser smtppassword True SMTP Server Connection for Emails Package.ConnectionManagers[DB1] SELECT * FROM Table1; Package.ConnectionManagers[FTPConnection] /data/ C:\data\ Receive Package.ConnectionManagers[SMTPConnection] noreply@mailserver.com user@example.com SSIS Task Notification Task has been completed successfully. #>