使用Powershell删除SSISDB目录中的SSIS文件夹

时间:2014-02-27 05:07:40

标签: powershell ssis

我正在尝试编写一个Powershell脚本来将项目重新部署到SSIS,而不会丢弃目录,我只想删除包含该项目的文件夹。

FolderToDrop in SSISDB

以下是在FolderToDrop上调用Drop()的代码:

$integrationServices = New-Object $Namespace".IntegrationServices" $sqlConnection
$catalog = $integrationServices.Catalogs["SSISDB"]
if ($catalog.Folders.Contains("FolderToDrop")) {
  $catalog.Folders["FolderToDrop"].Drop() 
}

引发的异常:

Exception calling "Drop" with "0" argument(s): "Operation 'Drop' on object 'CatalogFolder[@Name='FolderToDrop']' failed during execution."
At C:\Projects\Scripts\Deploy.ps1:36 char:29
+     $catalog.Folders["FolderToDrop"].Drop <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

关于我试图删除此文件夹缺少什么的任何想法?

3 个答案:

答案 0 :(得分:1)

在删除之前,您似乎需要从文件夹中删除环境和项目。

$folder = $catalog.Folders[$FolderName]

if($folder.Environments.Contains($EnvironmentName)) {
    $folder.Environments[$EnvironmentName].Drop()
}

if($folder.Projects.Contains($ProjectName)) {
    $folder.Projects[$ProjectName].Drop()
}

$folder.Drop()

答案 1 :(得分:1)

如果要删除所有文件夹,请指定环境/项目名称,您可以使用:

function CatalogFolderDrop($catalog, $folderName)
{
    while ($catalog.Folders[$folderName].Environments.Count -ne "0")
    {
        $env = $catalog.Folders[$folderName].Environments | Select-Object -First 1
        $catalog.Folders[$folderName].Environments[$env.Name].Drop();
    }
    while ($catalog.Folders[$folderName].Projects.Count -ne "0")
    {
        $prj = $catalog.Folders[$folderName].Projects | Select-Object -First 1
        $catalog.Folders[$folderName].Projects[$prj.Name].Drop();
    }
    $catalog.Folders[$folderName].Drop();
}

答案 2 :(得分:0)

    private void CatalogFolderDrop(String fdr) 
    {
        while (mtIntegrationServices.Catalogs["SSISDB"].Folders[fdr].Environments.Count > 0)
        {
            mtIntegrationServices.Catalogs["SSISDB"].Folders[fdr].Environments.ElementAt(0).Drop();
        }
        while (mtIntegrationServices.Catalogs["SSISDB"].Folders[fdr].Projects.Count > 0)
        {
            mtIntegrationServices.Catalogs["SSISDB"].Folders[fdr].Projects.ElementAt(0).Drop();
        }
        mtIntegrationServices.Catalogs["SSISDB"].Folders[fdr].Drop();
    }