使用powershell在SSISDB中创建一个文件夹

时间:2016-03-09 07:38:19

标签: sql powershell ssis ssis-2012 ssis-2008

我需要使用powershell在现有的SSISDB目录中创建一个文件夹。

我不想删除目录但需要连接。

1 个答案:

答案 0 :(得分:0)

如果目录不存在,它将创建目录,然后创建文件夹

# Variables
$SSISCatalog = "SSISDB"                    # Catalog Name
$CatalogPwd = "P@ssw0d1"                  # Password which is needed to encrypt the deployed packages
$FolderName = "Foldername"        #Folder Name

# Load the IntegrationServices Assembly
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.IntegrationServices") | Out-Null;

# Store the IntegrationServices Assembly namespace to avoid typing it every time
$ISNamespace = "Microsoft.SqlServer.Management.IntegrationServices"



# Create a connection to the server
$sqlConnectionString = "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;"
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString

# Create the Integration Services object
$integrationServices = New-Object $ISNamespace".IntegrationServices" $sqlConnection



# Drop the existing catalog if it exists
if ($integrationServices.Catalogs.Count -gt 0) { 

$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString


$ssisServer = New-Object Microsoft.SqlServer.Management.IntegrationServices.IntegrationServices $sqlConnection
$catalog = $ssisServer.Catalogs["SSISDB"]
# $catalog = $integrationServices.Catalogs[$SSICatalog]
#$catalog="Catalog[@Name='SSISDB']" 
}
else 
{# Provision a new SSIS Catalog
$catalog = New-Object $ISNamespace".Catalog" ($integrationServices, $SSISCatalog ,$CatalogPwd  )
$catalog.Create()
 }
Write-Host "Creating Folder " $FolderName " ..."

# Create a new folder
$folder = New-Object $ISNamespace".CatalogFolder" ($catalog, $FolderName, "Folder description")
$folder.Create()


Write-Host "All done."