none
Dealing with multivalued attributes in Granfeldt PowerShell MA RRS feed

  • Question

  • Hello,

    I'm trying to use Soren Granfeldt's PowerShell MA to pull some information from a legacy SQL Server (too old to use SQL Server MA) as part of a system migration. On the whole, it's working very well, but I've tried to add a new attribute to it and am running into some problems.

    The attribute is a multivalued string (actually an integer in the source db, but converting to a string since the MA requires that), and is the first multivalued attribute I've tried to use with this MA. When I run an import, the MA runs for the expected length of time but returns no objects.

    If I run the script in a PowerShell console, it does appear to spit the correct data out to the pipeline.

    If I set the script to return fixed test values for the multivalued attribute, it appears to work. This leads me to suspect that I'm somehow not correctly forming the object to put into the attribute (I'm trying to use an array of strings).

    Relevant code:

    Schema:

    $obj = New-Object -Type PSCustomObject
    @(
    #There are other attributes in here but they work fine.
        @{ Name='Group'; Type='String[]'; Value=('Value1','Value2') }
    ) | foreach { `
     $obj | Add-Member -Type NoteProperty -Name "$($_.Name)|$($_.Type)" -Value $_.Value
    }
    $obj

    Import script:

    # For each object

        $Groups = @()
        $GroupsConnection = New-Object System.Data.SqlClient.SqlConnection
        $GroupsConnection.ConnectionString = "Server = $DBHost; Database = $DBName; Integrated Security = True; User ID=$Username; Password=$Password"
        $GroupsConnection.Open()
        $GroupsCmd = $GroupsConnection.CreateCommand()
        $GroupsCmd.CommandText = "SELECT * FROM groups WHERE loginname='$AccountName'"
        $GroupsReader = $GroupsCmd.ExecuteReader()
        while ($GroupsReader.read()) {
          $Groups += $GroupsReader.GetValue(1).ToString()
        }
        $GroupsConnection.Close()
        $obj = @{
        # Other attributes in here, too
          'Group' = $Groups
        }
        $obj

    Can anybody see anything obviously wrong with this, or does anybody have an example of a working script?

    Many thanks in advance,
    Sean.

    Thursday, July 10, 2014 1:53 PM

All replies

  • The MA expects your script to return an array of object for multivalues. You should be able to return numbers also instead of just strings.

    Could you post an excerpt from the log for the PSMA? You can see here how to enable logging - http://blog.goverco.com/p/psmalogging.html


    Regards, Soren Granfeldt
    blog is at http://blog.goverco.com | facebook https://www.facebook.com/TheIdentityManagementExplorer | twitter at https://twitter.com/#!/MrGranfeldt


    Friday, July 18, 2014 7:37 AM
  • Did you manage to resolve this?

    Regards, Soren Granfeldt
    blog is at http://blog.goverco.com | facebook https://www.facebook.com/TheIdentityManagementExplorer | twitter at https://twitter.com/#!/MrGranfeldt

    Friday, July 25, 2014 6:46 AM
  • I struggled with this as well.

    This works:

    Import

    $obj= @{}

    $obj.Id = "1"

    $obj.objectClass = "user"

    $obj."[DN]"= "CN=Luke Skywalker,OU=Normal Users,DC=domain,DC=com"

    $obj.sAMAccountName = "LS"

    $obj.displayName = "Luke Skywalker"

    $obj.proxyaddresses = "SMTP:lk@light.side ","smtp:lk@light.side","smtp:lk@light.side"

    $obj

     

    Schema

    $obj= New-Object -Type PSCustomObject

    $obj| Add-Member -Type NoteProperty -Name "Anchor-id|String" -Value "1"

    $obj| Add-Member -Type NoteProperty -Name "objectClass|String" -Value "user"

    $obj| Add-Member -Type NoteProperty -Name "sAMAccountName|String" -Value "lk"

    $obj| Add-Member -Type NoteProperty -Name "displayName|String" -Value "Luke Skywalker"

    $obj| Add-Member -Type NoteProperty -Name "firstname|String" -Value "Luke"

    $obj| Add-Member -Type NoteProperty -Name "proxyaddresses|String[]" -Value "SMTP:lk@light.side ","smtp:lk@light.side","smtp:lk@light.side"

    $obj 


    /Frederik Leed

    Wednesday, April 27, 2016 11:18 AM