Quantcast
Viewing all articles
Browse latest Browse all 6944

Dealing with multivalued attributes in Granfeldt PowerShell MA

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.


Viewing all articles
Browse latest Browse all 6944

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>