【发布时间】:2016-11-05 14:59:20
【问题描述】:
有没有办法使用 PowerShell 从 SSIS 目录中的包中获取包 XML,但无需下载和提取项目?我想在 XML 文档中搜索某些字符串。
################################
########## PARAMETERS ##########
################################
$SsisServer = ".\sql2016"
############################
########## SERVER ##########
############################
# Load the Integration Services Assembly
$SsisNamespace = "Microsoft.SqlServer.Management.IntegrationServices"
[System.Reflection.Assembly]::LoadWithPartialName($SsisNamespace) | Out-Null;
# Create a connection to the server
$SqlConnectionstring = "Data Source=" + $SsisServer + ";Initial Catalog=master;Integrated Security=SSPI;"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnectionstring
# Create the Integration Services object
$IntegrationServices = New-Object $SsisNamespace".IntegrationServices" $SqlConnection
# Check if connection succeeded
if (-not $IntegrationServices)
{
Throw [System.Exception] "Failed to connect to server $SsisServer "
}
#############################
########## CATALOG ##########
#############################
# Create object for SSISDB Catalog
$Catalog = $IntegrationServices.Catalogs["SSISDB"]
# Check if the SSISDB Catalog exists
if (-not $Catalog)
{
Throw [System.Exception] "SSISDB catalog doesn't exist!"
}
##########################
########## LOOP ##########
##########################
foreach ($Folder in $Catalog.Folders)
{
Write-Host $Folder.Name
foreach ($Project in $Folder.Projects)
{
Write-Host " - " $Project.Name
foreach ($Package in $Project.Packages)
{
Write-Host " - " $Package.Name
# HOW TO GET PACKAGE XML???
# Not working:
# Exception calling "Serialize" with "1" argument(s):
# "The parameter 'sink.Action' is invalid."
#$sb = New-Object System.Text.StringBuilder
#$sw = New-Object System.IO.StringWriter($sb)
#$writer = New-Object System.Xml.XmlTextWriter($sw)
#$xml = $Package.Serialize($writer)
}
}
}
【问题讨论】:
标签: xml powershell ssis