2014-02-27 110 views
0

我正在嘗試編寫一個Powershell腳本來重新部署項目到SSIS並且不會毀壞目錄我只是想刪除包含該項目的文件夾。使用Powershell刪除SSISDB目錄中的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 

任何想法,以什麼我缺少努力刪除這個文件夾?

回答

0

看起來您需要在刪除文件夾之前刪除環境和項目。

$folder = $catalog.Folders[$FolderName] 

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

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

$folder.Drop() 
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(); 
    } 
相關問題