使用PowerShell 2.0创建SSIS文件夹

使用PowerShell 2.0创建SSIS文件夹,ssis,sql-server-2012,powershell-2.0,Ssis,Sql Server 2012,Powershell 2.0,我正在寻找一个信息,可能看起来很容易获得,但我不能把我的手放在它 我想通过Powershell脚本在SSISDB目录中创建一个文件夹,但我收到一个错误消息,说Powershell无法加载程序集:Microsoft.sqlserver.BatchParser和Microsoft.sqlserver.BatchParserClient,即使它们存在于C:\Windows\Assembly中 但实际上我怀疑PowerShell运行的版本太旧了,即2.0。是否有人可以确认我们可以使用2.0 Powers

我正在寻找一个信息,可能看起来很容易获得,但我不能把我的手放在它

我想通过Powershell脚本在SSISDB目录中创建一个文件夹,但我收到一个错误消息,说Powershell无法加载程序集:Microsoft.sqlserver.BatchParser和Microsoft.sqlserver.BatchParserClient,即使它们存在于C:\Windows\Assembly中

但实际上我怀疑PowerShell运行的版本太旧了,即2.0。是否有人可以确认我们可以使用2.0 Powershell版本创建SSIS目录文件夹


感谢您的帮助

因为没有提供任何代码,所以调试它为什么不工作非常困难。但是,这段代码是我在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类
  • 将其指向实际目录(假定已创建)
  • 测试文件夹是否已经存在
  • 如果文件夹不存在,请创建它
  • 如果文件夹存在,请更新说明