0
  • Question: This Powershell code have manual values defined "Value 1 & value 2" , want these two to be from CSV file.
#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 

Desired Output.

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}}
2
  • 1
    What have you tried already?
    – harrymc
    Commented Jun 3, 2022 at 9:17
  • create a csv with a id, name and type column and use Import-CSV
    – SimonS
    Commented Jun 3, 2022 at 9:18

1 Answer 1

0

You can continue on with Import-CSV in a couple of ways, here's some examples:

$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
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .