有没有办法使用 PowerShell 从 SSIS 目录中的包中获取包 XML,但无需下载和解压缩项目?我想在 XML 文档中搜索某些字符串。
################################
########## PARAMETERS ##########
################################
$SsisServer = ".\sql2016"
############################
########## SERVER ##########
############################
# Load the Integration Services Assembly
$SsisNamespace = "Microsoft.SqlServer.Management.IntegrationServices"
[System.Reflection.Assembly]::LoadWithPartialName($SsisNamespace) | Out-Null;
# Create a connection to the server
$SqlConnectionstring = "Data Source=" + $SsisServer + ";Initial Catalog=master;Integrated Security=SSPI;"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnectionstring
# Create the Integration Services object
$IntegrationServices = New-Object $SsisNamespace".IntegrationServices" $SqlConnection
# Check if connection succeeded
if (-not $IntegrationServices)
{
Throw [System.Exception] "Failed to connect …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的SSIS目录环境导出到JSON文件(使用PowerShell).当我选择正确的列时,我将"String"和"Int16"视为Type的值:
但是当我使用ConvertTo-Json转换为JSON时,它显示的是int值而不是字符串值:
有什么建议?
如何遍历 JSON 文件中的所有项目?当前代码只是将所有名称写在一个大行上:
Get-Content -Raw -Path c:\temp\Environments.Generic.json | ConvertFrom-Json | ForEach-Object {
Write-Host $_.Name
}
Run Code Online (Sandbox Code Playgroud)
json文件:
[
{
"Name":"EnableRetry",
"Description":"Enable retry for Webservice Task",
"Type":"Boolean",
"Sensitive":false,
"Value":true
},
{
"Name":"FolderStageFiles",
"Description":"Location of stage files",
"Type":"String",
"Sensitive":false,
"Value":"d:\\sources\\"
},
{
"Name":"FtpPassword",
"Description":"Secret FTP password",
"Type":"String",
"Sensitive":true,
"Value":"Welcome1"
}
]
Run Code Online (Sandbox Code Playgroud) 我有一个 Azure 对象(虚拟机、数据仓库或分析服务)的集合,我想遍历该集合,但也过滤掉具有特定标签的对象。
例如,获取所有没有名为“Environment”且值为“Production”的标签的Analysis Services 。
如何指定Where-Object过滤器(尝试了几种方法都没有成功)
cls
# Login to Azure
#Login-AzureRmAccount | Out-Null
# Selecting the right subscription
#Select-AzureRmSubscription -SubscriptionName "MySubscription" | Out-Null
# Get all my Analysis Services, but leave out those with the tag Environment=Production
$AnalysisServicesServers = Get-AzureRmAnalysisServicesServer | Where-Object {$_.Tag -notcontains @{Environment="Production";}}
# Loop Through the collection and to something
foreach ($AnalysisServicesServer in $AnalysisServicesServers)
{
$AnalysisServicesServer # Show all properties
Write-Host "1 Name $($AnalysisServicesServer.Name)" # Show Name
Write-Host "2 Tags count [$($AnalysisServicesServer.Tag.Keys.Count)]" # …Run Code Online (Sandbox Code Playgroud)