Powershell 通过power shell检索SSIS 2012 environmentvariable.name
我们正在使用power shell部署我们的2012 SSIS包,并在SSIS 2012服务器上具有环境变量。现在,在项目部署过程中,我正试图循环遍历$environment.variables中每个$variable的环境变量集合中的每个变量。这没问题。我可以看到EnvironmentVariable[@Name='something']..。但是尝试通过$variable.Name或$variable.Key从变量中检索名称something不起作用。我尝试过循环使用$environment.Variables.Keys,但仍然一无所获。在过去的几年里,我一直在使用NANT,所以我的能量壳技能有点弱,但有什么我没有看到的吗 提前感谢,, 安东尼 正在添加现有powershell脚本的代码段。粗体$variable.Name在CreateETLPackages任务中不起作用。有很多设置和其他脚本从这个脚本调用,所以我没有包括所有内容。当$variable.Name在调试语句中返回时,它将返回我在原始帖子中提到的EnvironmentVariable[@Name='something']: 任务CreateSissiFolder-依赖CreateSissiCatalog{ if!$script:ssiscanbedployed{return}Powershell 通过power shell检索SSIS 2012 environmentvariable.name,powershell,ssis,Powershell,Ssis,我们正在使用power shell部署我们的2012 SSIS包,并在SSIS 2012服务器上具有环境变量。现在,在项目部署过程中,我正试图循环遍历$environment.variables中每个$variable的环境变量集合中的每个变量。这没问题。我可以看到EnvironmentVariable[@Name='something']..。但是尝试通过$variable.Name或$variable.Key从变量中检索名称something不起作用。我尝试过循环使用$environment
# Create the project for the packages in the catalog
$catalog = $script:SSISCatalog
if ($catalog.Folders.Count -eq 0) {
Write-Host "Creating folder $SSISFolderName ..."
$script:SSISFolder = New-Object "Microsoft.SqlServer.Management.IntegrationServices.CatalogFolder" ($catalog, $SSISFolderName, "Folder for EDGE ETL packages")
$script:SSISFolder.Create()
Write-Host "... done"
} else {
Write-Host "SSIS folder $SSISFolderName already exists; skipping create"
}
# Create the environment in the project
$folder = $script:SSISFolder
$environment = $folder.Environments[$SSISEnvironmentName]
if ($environment -eq $null) {
# Create the environment
Write-Host "Creating environment $SSISEnvironmentName ..."
$environment = New-Object "Microsoft.SqlServer.Management.IntegrationServices.EnvironmentInfo" ($folder, $SSISEnvironmentName, "Environment to configure the SSIS packages")
$environment.Create()
Write-Host "... done"
# Now create the variables (Constructor args: variable name, type, default value, sensitivity, description)
$environment.Variables.Add("TestDatabase", [System.TypeCode]::String, "Data Source=$SSISServerName.TestDatabase;User ID=<USERNAME>;Password=<PASSWORD>;Initial Catalog=EdgeAviTrack;Provider=SQLNCLI11.1;Persist Security Info=True;Auto Translate=False;", $false, "Connection string for TestDatabase database")
$environment.Alter()
} else {
Write-Host "Environment $SSISEnvironmentName already exists; skipping create"
}
# Get list of ETL .ispac files in the solution
$SSISProjects = GetListOfDeploymentFiles "*.ispac"
if ($SSISProjects -ne $null) {
$folder = $script:SSISFolder
$environment = $folder.Environments[$SSISEnvironmentName]
if ($folder -ne $null) {
foreach ($file in $SSISProjects) {
# Read the ispac file, and deploy it to the folder
[byte[]] $projectFile = [System.IO.File]::ReadAllBytes($file.FullName)
$nameParts = $file.Name.split(".")
$curProjectName = [string]::join(".", $nameParts[0..($nameParts.length - 2)])
Write-Debug "Deploying SSIS project $curProjectName"
$project = $folder.DeployProject($curProjectName, $projectFile)
if ($project.Status -ne "Success") {
Write-Error "SSIS packages did not deploy correctly!"
} else {
# Get the full information set, rather than the short version returned from DeployProject
$project = $folder.Projects[$curProjectName]
}
# Connect the project to the environment to stitch up all the connection strings
if ($project.References.Item($SSISEnvironmentName, ".") -eq $null) {
Write-Host "Adding environment reference to $SSISEnvironmentName ..."
$project.References.Add($SSISEnvironmentName)
$project.Alter()
Write-Host "... done"
}
# Connect all the project parameters to the environment variables
Write-Host "Adding connection string references to environment variables ..."
foreach($varialble in $environment.Variables) {
try {
$project.Parameters["CM." + **$varialble.Name** + ".ConnectionString"].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Referenced, **$variable.Name**)
}
catch {
Write-Debug "Unable to set connection string **$variable.Name** on SSIS project $curProjectName"
}
}
$project.Alter()
Write-Host "... done"
}
}
}
}
任务CreateSissionEnvironment-依赖CreateSissionFolder{
if!$script:ssiscanbedployed{return}
# Create the project for the packages in the catalog
$catalog = $script:SSISCatalog
if ($catalog.Folders.Count -eq 0) {
Write-Host "Creating folder $SSISFolderName ..."
$script:SSISFolder = New-Object "Microsoft.SqlServer.Management.IntegrationServices.CatalogFolder" ($catalog, $SSISFolderName, "Folder for EDGE ETL packages")
$script:SSISFolder.Create()
Write-Host "... done"
} else {
Write-Host "SSIS folder $SSISFolderName already exists; skipping create"
}
# Create the environment in the project
$folder = $script:SSISFolder
$environment = $folder.Environments[$SSISEnvironmentName]
if ($environment -eq $null) {
# Create the environment
Write-Host "Creating environment $SSISEnvironmentName ..."
$environment = New-Object "Microsoft.SqlServer.Management.IntegrationServices.EnvironmentInfo" ($folder, $SSISEnvironmentName, "Environment to configure the SSIS packages")
$environment.Create()
Write-Host "... done"
# Now create the variables (Constructor args: variable name, type, default value, sensitivity, description)
$environment.Variables.Add("TestDatabase", [System.TypeCode]::String, "Data Source=$SSISServerName.TestDatabase;User ID=<USERNAME>;Password=<PASSWORD>;Initial Catalog=EdgeAviTrack;Provider=SQLNCLI11.1;Persist Security Info=True;Auto Translate=False;", $false, "Connection string for TestDatabase database")
$environment.Alter()
} else {
Write-Host "Environment $SSISEnvironmentName already exists; skipping create"
}
# Get list of ETL .ispac files in the solution
$SSISProjects = GetListOfDeploymentFiles "*.ispac"
if ($SSISProjects -ne $null) {
$folder = $script:SSISFolder
$environment = $folder.Environments[$SSISEnvironmentName]
if ($folder -ne $null) {
foreach ($file in $SSISProjects) {
# Read the ispac file, and deploy it to the folder
[byte[]] $projectFile = [System.IO.File]::ReadAllBytes($file.FullName)
$nameParts = $file.Name.split(".")
$curProjectName = [string]::join(".", $nameParts[0..($nameParts.length - 2)])
Write-Debug "Deploying SSIS project $curProjectName"
$project = $folder.DeployProject($curProjectName, $projectFile)
if ($project.Status -ne "Success") {
Write-Error "SSIS packages did not deploy correctly!"
} else {
# Get the full information set, rather than the short version returned from DeployProject
$project = $folder.Projects[$curProjectName]
}
# Connect the project to the environment to stitch up all the connection strings
if ($project.References.Item($SSISEnvironmentName, ".") -eq $null) {
Write-Host "Adding environment reference to $SSISEnvironmentName ..."
$project.References.Add($SSISEnvironmentName)
$project.Alter()
Write-Host "... done"
}
# Connect all the project parameters to the environment variables
Write-Host "Adding connection string references to environment variables ..."
foreach($varialble in $environment.Variables) {
try {
$project.Parameters["CM." + **$varialble.Name** + ".ConnectionString"].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Referenced, **$variable.Name**)
}
catch {
Write-Debug "Unable to set connection string **$variable.Name** on SSIS project $curProjectName"
}
}
$project.Alter()
Write-Host "... done"
}
}
}
}好的,我发现了问题。看起来我在尝试我需要使用$$object.Name来获取我需要的内容。感谢那些伸出援手寻求帮助的人 谢谢,
安东尼好的,我发现了我的问题。看起来我在尝试我需要使用$$object.Name来获取我需要的内容。感谢那些伸出援手寻求帮助的人 谢谢,
Anthony这个问题是关于2012 SSIS环境变量/配置的,它与操作系统的环境变量完全无关。能否提供更多的powershell脚本?我启动了SQLPS,但没有看到与integration services目录对应的任何内容。我确实看到了Databases\SSIDB,但我希望有一些定制的东西。billinkc您有机会查看我发送的脚本吗?我还在想办法解决这个问题-谢谢,这个问题是关于2012 SSIS环境变量/配置的,它与操作系统的环境变量完全无关。能否提供更多的powershell脚本?我启动了SQLPS,但没有看到与integration services目录对应的任何内容。我确实看到了Databases\SSIDB,但我希望有一些定制的东西。billinkc您有机会查看我发送的脚本吗?我还在想办法解决这个问题-谢谢你,安东尼