Hi,
I have the following PowerShell script which :
$PsFileDir="C:\MyFolder\01_ETL\PS\PkgExec"
$SlnDir="C:\MyFolder\TestAutomatPowerShell\MyFolder\MyProj.dtproj"
$PkgDir="C:\MyFolder\TestAutomatPowerShell\MyFolder"
$TargetSrv="MySQLServer"
$DevEnvPath="\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"
#Build the project
Write-Host "Building the project ..."&"${env:ProgramFiles(x86)}${DevEnvPath}" ${SlnDir} /build
Start-Sleep -s 180
# Load the IntegrationServices Assembly
$loadStatus = [Reflection.Assembly]::Load("Microsoft"+".SqlServer.Management.IntegrationServices" +", Version=11.0.0.0, Culture=neutral" +", PublicKeyToken=89845dcd8080cc91")
# Store the IntegrationServices Assembly namespace to avoid typing it every time
$ISNamespace = "Microsoft.SqlServer.Management.IntegrationServices"
Write-Host "Connecting to server ..."
#Connect to SQL server which has SSIS Package
$sqlConnectionString = "Data Source=$TargetSrv;Initial Catalog=master;Integrated Security=SSPI;Trusted_Connection=True;"
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString
# Create the Integration Services object
$ssis = New-Object $ISNamespace".IntegrationServices" $con
#Connect to Integration Service
$ssisServer = New-Object Microsoft.SqlServer.Management.IntegrationServices.IntegrationServices $sqlConnection
$ssisCatalog = $ssisServer.Catalogs["SSISDB"]
#Check if Folder is already present, if not create one
Write-Host "Creating MyProj project folder ..."
$ssisFolderName = "MyProj"
$ssisFolder = $ssisCatalog.Folders.Item($ssisFolderName)
# Read the project file, and deploy it to the folder
Write-Host "Deploying MyProj project ..."
[byte[]] $projectFile = [System.IO.File]::ReadAllBytes("C:\MyFolder\TestAutomatPowerShell\MyProj\bin\Development\MyProj.ispac")
$ssisFolder.DeployProject("MyProj", $projectFile)
# Creating an environment
Write-Host "Creating MyProj environment ..."
$environment = New-Object $ISNamespace".EnvironmentInfo" ($ssisFolder, "MyProj", "Projet New MyProj")
$environment.Create()
Write-Host "Adding server variables ..."
# Adding variable to our environment
# Constructor args: variable name, type, default value, sensitivity, description
$environment.Variables.Add("L_7ZIP_PATH", [System.TypeCode]::String, "C:\MyFolder\01_ETL\Tools", $false, "")
$environment.Variables.Add("L_DWHLOADER_PATH", [System.TypeCode]::String, "C:\Program Files\Microsoft SQL Server Parallel Data Warehouse\100", $false, "")
$environment.Variables.Add("L_PDW_PWD", [System.TypeCode]::String, "MyPWD", $false, "")
$environment.Variables.Add("L_PDW_USER", [System.TypeCode]::String, "MyUSR", $false, "")
$environment.Variables.Add("L_SRC_FILES_PATH", [System.TypeCode]::String, "C:\MyFolder\01_ETL", $false, "")
$environment.Alter()
#xxxx
Write-Host "Adding environment reference to project ..."
# making project refer to this environment
$project = $ssisFolder.Projects["MyProj"]
$project.References.Add("MyProj", "MyProj")
$project.Alter()
Write-Host "Adding reference to variables ..."
$project.Parameters["L_7ZIP_PATH"].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Referenced, "L_7ZIP_PATH")
$project.Parameters["L_DWHLOADER_PATH"].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Referenced, "L_DWHLOADER_PATH")
$project.Parameters["L_PDW_PWD"].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Referenced, "L_PDW_PWD")
$project.Parameters["L_PDW_USER"].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Referenced, "L_PDW_USER")
$project.Parameters["L_SRC_FILES_PATH"].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Referenced, "L_SRC_FILES_PATH")
$TABLENAME=(get-childitem $PkgDir | ?{!$_.PSIsContainer -and $_.name -match "\\*.dtsx"})
$TotStartTime=Get-Date
Write-output "Total Start Time : $TotStartTime"
foreach ($pkg in $TABLENAME)
{
$StartTime=Get-Date
Write-output "Executing $pkg ..."
# Run the package
Write-Host "Running package ..."
# When executing, we need to specify two parameters
# 1 arg is a bool representing whether we want to run
# 32bit runtime on 64 bit server
# 2 arg is a reference to an environment if this package depends on it
$pkgToExec = $project.Packages[$pkg.Name]
Write-output "Package Name : " $pkgToExec
# retrieving environment reference
$environmentReference = $project.References.Item("MyProj", "MyProj")
$environmentReference.Refresh()
$executionId = $pkgToExec.Execute("false", $environmentReference)
$EndTime=Get-Date
$ElapsedTime = ($EndTime - $StartTime)
Write-output "${pkg},${ElapsedTime},${StartTime}, ${EndTime}" >>$PsFileDir\Logs\$pkg.log
}
$TotEndTime=Get-Date
$TotElapsedTime = ($TotEndTime - $TotStartTime)
Write-output "Total End Time : TotEndTime"
Write-output "TotalElapsedTime : $TotElapsedTime"
- Build a SSIS project
- Deploy the project to SSIS Catalog
- Run each of the packages in the solution
I don't have errors when executing the PowerShell.
But none of my packages succeed.
Any expressions using Project variables are not evaluated right because the value from the Project variable is not found. I have blanks anywhere I use Project variables.
Any idea ?
Thanks for your help.
Regards,
Bertrandr