- 질문: 이 Powershell 코드에는 "값 1 및 값 2"로 정의된 수동 값이 있으며, 이 두 값을 CSV 파일에서 가져오려고 합니다.
#Value 1
$blockedConnector1 = [pscustomobject]@{
id = "/providers/Microsoft.PowerApps/apis/shared_salesforce"
name = "Salesforce"
type = "Microsoft.PowerApps/apis"
}
#value 2
$blockedConnector2 = [pscustomobject]@{
id = "/providers/Microsoft.PowerApps/apis/shared_postgresql"
name = "PostgreSQL"
type = "Microsoft.PowerApps/apis"
}
#Grouping of Connectors
$blockedConnectors = @()
$blockedConnectors += $blockedConnector1
$blockedConnectors += $blockedConnector2
$blockedConnectorGroup = [pscustomobject]@{
classification = "Blocked"
connectors = $blockedConnectors
}
$blockedConnectorGroup | Format-List
원하는 출력.
classification : Blocked
connectors : {@{id=/providers/Microsoft.PowerApps/apis/shared_salesforce; name=Salesforce; type=Microsoft.PowerApps/apis}, @{id=/providers/Microsoft.PowerApps/apis/shared_postgresql; name=PostgreSQL;type=Microsoft.PowerApps/apis}}
답변1
Import-CSV
몇 가지 방법 으로 계속할 수 있습니다 . 다음은 몇 가지 예입니다.
$blockedConnectors = Import-CSV 'C:\path\to\file.csv'
# Example 1: import straight into your group
$blockedConnectorGroup = [pscustomobject]@{
classification = "Blocked"
connectors = $blockedConnectors
}
# Example 2: only import specific objects from the csv
$SalesForce = $blockedConnectors | Where-Object Name -EQ 'SalesForce'
$Postgres = $blockedConnectors | Where-Object Name -EQ 'PostgreSQL'
$blockedConnectorGroup = [pscustomobject]@{
classification = "Blocked"
connectors = $SalesForce,$PostGres
}