简体   繁体   中英

Create a folder in SSISDB using powershell

I need to create a folder in a existing SSISDB catalog using powershell.

I don't want to delete the catalog but need the connection.

It will create a catalog if catalog not presents and then it creates a folder

# 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."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM