Piping SQL query result into another command in PowerShell
<p>I would like to create a module, which would have several functions related to user provisioning. The data would be pulled from a SQL database and piped as a result into an AD command (importing AD module is omitted in this example).
A sample is below:
Lets consider a table with users.</p>

<blockquote>
  <p>Id, username, firstname, lastname, signed<br>
      1, joed, joe, doe, NULL<br>
      2, janes, jane, smith, 2/2/12<br>
      3, nickc, nick, cook, NULL<br>
      4, robh, rob, hunt, 3/3/13</p>
</blockquote>

<pre><code>Function Get-ContractSigned {
[CmdletBinding()]
param ()

BEGIN { 
# SQL Connection #
$server   = "SERVER"
$database = "Database" 
# formatting the table headers to correspond with Identity parameter of AdUser cmdlets
$q_contractSigned = "SELECT USERNAME as IDENTITY, FIRSTNAME, LASTNAME
      FROM EMPLOYEES
      WHERE signed IS NOT NULL"
$sqlConn = New-Object System.Data.SqlClient.SqlConnection
$sqlConn.ConnectionString = "Server=$server;Initial Catalog=$database;Integrated Security=true"
$sqlConn.Open()

# SQL command
$sqlCmd = New-Object System.Data.SqlClient.SqlCommand
$sqlCmd.Connection = $sqlConn
$sqlcmd.CommandText = $q_contractSigned

PROCESS {
 $adp = New-Object System.Data.SqlClient.SqlDataAdapter $sqlcmd
 $dataSet = New-Object System.Data.DataSet
 $adp.Fill($dataSet) | Out-Null
 $dataSet.Tables
}

END {
   $sqlConn.Close()
}
</code></pre>

<p>At this point the function displays the following output:</p>

<blockquote>
  <p>Get-ContractSigned</p>

<pre><code>IDENTITY  FIRSTNAME   LASTNAME
janes       Jane        Smith
robh        Rob         Hunt
</code></pre>
</blockquote>

<p>I would like to be able to do the following:</p>

<pre><code>Get-ContractSigned | Enable-ADUser
</code></pre>

<p>but am not sure how to process this System.Data.DataTable </p>

<p>Any suggestions are greatly appreciated.</p>