gpt4 book ai didi

powershell - 通过Power Shell检索SSIS 2012 environmentvariable.name

转载 作者:行者123 更新时间:2023-12-03 00:20:17 25 4
gpt4 key购买 nike

我们正在使用Power Shell部署我们的2012 SSIS软件包,并在SSIS 2012 Server上具有环境变量。现在,在项目部署期间,我试图遍历环境变量集合中的每个变量(foreach($ environment.Variables中的$ variable))。没问题我可以看到“EnvironmentVariable [@Name ='something']”...。但是,尝试通过$ variable.Name或$ variable.Key从变量中检索名称(“something”)无效。我尝试遍历$ environment.Variables.Keys,仍然没有。自从我过去几年一直使用NANT以来,我的动力壳技能就有些薄弱,但是我只是看不到某些东西吗?

提前致谢,
安东尼

添加现有Power Shell脚本的代码段。加粗的$ variable.Name在CreateETLPackages任务中不起作用。该脚本有很多设置和其他脚本,因此我没有包含所有内容。当$ variable.Name在调试语句中返回时,它返回“EnvironmentVariable [@Name ='something']”,正如我在原始帖子中提到的那样:

任务CreateSSISFolder-取决于CreateSSISCatalog {
如果(!$ script:SSISCanBeDeployed){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"
}

}

任务CreateSSISEnvironment-取决于CreateSSISFolder {
如果(!$ script:SSISCanBeDeployed){return}
# 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"
}

}

任务CreateETLPackages-取决于CreateSSISFolder,CreateSSISEnvironment {
如果(!$ script:SSISCanBeDeployed){return}
# 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)来获取需要的东西。感谢那些伸出援手的人。

谢谢,
安东尼

关于powershell - 通过Power Shell检索SSIS 2012 environmentvariable.name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11893586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com