- Frage: Dieser Powershell-Code hat manuell definierte Werte „Wert 1 und Wert 2“. Diese beiden sollen aus einer CSV-Datei stammen.
#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
Gewünschte Ausgabe.
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}}
Antwort1
Import-CSV
Sie können auf verschiedene Arten fortfahren , hier sind einige Beispiele:
$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
}