我想创建一个模块,它有几个与用户配置相关的功能。数据将从SQL数据库中提取并作为结果传送到AD命令(在此示例中省略了导入AD模块)。 样本如下: 让我们考虑一个包含用户的表。
ID,用户名,名字,姓氏,签名
1,joed,joe,doe,NULL
2,janes,jane,smith,2/2/12
3,nickc,nick,cook,NULL
4,抢劫,抢劫,打猎,2013年3月3日
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()
}
此时该功能显示以下输出:
GET-ContractSigned
IDENTITY FIRSTNAME LASTNAME janes Jane Smith robh Rob Hunt
我希望能够做到以下几点:
Get-ContractSigned | Enable-ADUser
但我不知道如何处理这个System.Data.DataTable
非常感谢任何建议。