【问题标题】:Creating SSIS Folder with PowerShell 2.0使用 PowerShell 2.0 创建 SSIS 文件夹
【发布时间】:2018-06-13 12:51:29
【问题描述】:
我正在寻找可能看起来很容易获得但我无法获得的信息。
我想通过 Powershell 脚本在 SSISDB 目录中创建一个文件夹,但我收到一条错误消息,指出 Powershell 无法加载程序集:Microsoft.sqlserver.BatchParser 和 Microsoft.sqlserver.BatchParserClient,即使它们存在于 C 中:\Windows\Assembly。
但实际上我怀疑 PowerShell 运行的版本太旧,即 2.0。谁能确认我们可以使用 2.0 Powershell 版本创建 SSIS 目录文件夹?
感谢您的帮助
【问题讨论】:
标签:
ssis
sql-server-2012
powershell-2.0
【解决方案1】:
由于没有提供代码,因此调试它为什么不起作用是非常具有挑战性的。但是,我在 ispac 部署中使用此代码。
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.IntegrationServices") | Out-Null
#this allows the debug messages to be shown
$DebugPreference = "Continue"
# Retrieves a Integration Services CatalogFolder object
# Creates one if not found
Function Get-CatalogFolder
{
param
(
[string] $folderName
, [string] $folderDescription
, [string] $serverName = "localhost\dev2012"
)
$connectionString = [String]::Format("Data Source={0};Initial Catalog=msdb;Integrated Security=SSPI;", $serverName)
$connection = New-Object System.Data.SqlClient.SqlConnection($connectionString)
$integrationServices = New-Object Microsoft.SqlServer.Management.IntegrationServices.IntegrationServices($connection)
# The one, the only SSISDB catalog
$catalog = $integrationServices.Catalogs["SSISDB"]
$catalogFolder = $catalog.Folders[$folderName]
if (-not $catalogFolder)
{
Write-Debug([System.string]::Format("Creating folder {0}", $folderName))
$catalogFolder = New-Object Microsoft.SqlServer.Management.IntegrationServices.CatalogFolder($catalog, $folderName, $folderDescription)
$catalogFolder.Create()
}
else
{
$catalogFolder.Description = $folderDescription
$catalogFolder.Alter()
Write-Debug([System.string]::Format("Existing folder {0}", $folderName))
}
return $catalogFolder
}
$folderName = "ProdSupport HR export"
$folderDescription = "Prod deployment check"
$serverName = "localhost\dev2012"
$catalogFolder = Get-CatalogFolder $folderName $folderDescription $serverName
在 PowerShell 中可能有更优雅的方式来执行此操作,但这可以完成工作。逻辑阅读上面的代码
- 创建与相关服务器的 SqlClient 连接
- 实例化 IntegrationServices 类
- 将其指向实际目录(假设已创建)
- 测试文件夹是否已经存在
- 如果文件夹不存在,则创建它
- 如果文件夹存在,更新说明