You may want to consider an alternate approach of importing the AD information into SQL Server. One way to do so:
Create a table to hold AD data in SQL Server:
Create table qaduser_fill
(
samid varchar(255),
customerNum varchar(255)
)
#Get AD info:
get-qaduser | select NTAccountName, customerNumber | export-csv -noTypeInfo ./qaduser.csv
#Cleanup CSV file for import into SQL Server by removing double quotes
(Get-Content C:\Users\Public\qaduser.csvv) | foreach {$_ -replace '"'} | Set-Content C:\Users\Public\qaduser.csv
Define query to import data:
$query = @"
BULK INSERT mydatabaseName.dbo.qaduser_fill FROM 'C:\Users\Public\qaduser.csv'
WITH (FIRSTROW = 2, FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')
"@
Execute query using Invoke-SqlCmd or Invoke-Sqlcmd2:
http://poshcode.org/1791 Invoke-SqlCmd2 -ServerInstance "WIN2K8R2\SQL2K8" -Database mydatabaseName-Query $query
Use a standard SQL join to join the data:
SELECT *
FROM mydatabaseName.dbo.OrginalInfo o
JOIN qaduser_fill q ON
o.id = q.samid
You could use Invoke-Sqlcmd or Invoke-Sqlcmd2 to call the query in PowerShell