我有以下脚本允许我从 MS SQL Db 获取 MAC 地址。
Function Get-MAC ($Server)
{
$SQLServer = "TVEAPP02" #use Server\Instance for named SQL instances!
$SQLDBName = "EuropeanMacs"
$SqlQuery = "select MAC from dbo.tbl_MAC WHERE HOST = '$Server'"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$DataSet.Tables[0]
}
GET-MAC Computerrname
我得到了这个结果的例子:
获取 MAC 1IT001 2
苹果电脑
--- F4:CE:46:2C:21:FE
F4:CE:46:2C:21:FE
我怎样才能从这个结果中得到第一个或第二个 MAC?我的意思是我想在 $MAC1 和 $MAC2 中得到结果...
对不起我的英语,谢谢你的阅读。