0

I've queried certain information from an SQL database and put it into a variable named $tablevalue. Now I want add new column on the output and that requires querying active directory for the status of a computer object

$tablevalue has a typename System.Data.DataRow

Sample query:

$tablevalue | select netbios_name0, client0, @{n='ADComputer_Enabled';e={
    (Get-ADComputer -Filter {name -like {$_.netbios_name0} | select Enabled)
}}

Desired output:

netbios_name0, client0, ADComputer_enabled
computer1      version1 True
computer1      version1 False
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
jcaloy
  • 1
  • 1
  • 3
  • 1
    `select Enabled` -> `select -Expand Enabled`? – Ansgar Wiechers Nov 02 '17 at 23:15
  • hello Ansgar thanks for the feedback but i think the issue is with this expression. (Get-ADComputer -Filter {name -like {$_.netbios_name0} – jcaloy Nov 03 '17 at 06:34
  • the $_.netbios_name is not being recognized, i'm unable to input this to the get-adcomputer – jcaloy Nov 03 '17 at 06:36
  • $tablevalue | select netbios_name0, client0, @{n='ADComputer_Enabled';e={ (Get-ADComputer -Filter {name -like {$_.netbios_name0} | select Enabled) }} – jcaloy Nov 03 '17 at 06:38
  • a simple piping of the same script will work fine example: $tablevalue | select netbios_name0, client0, @{n='ADComputer_Enabled';e={(write-host $_.netbios_name0)}} the idea is that each netbios_name0 in the $tablevalue, i want to query computer object attribute value for "enabled" in active directory using get-adcomputer cmdlet and add a column in the final output to display netbiosname, client0 from $tablevalue plus a new column name ADComputer_Enabled that contains the status of each machine in terms ADcomputer attribute "Enabled" (True/False) – jcaloy Nov 03 '17 at 06:47
  • `Get-ADComputer -Filter {name -like {$_.netbios_name0} | select Enabled` -> `Get-ADComputer -Filter "name -like '*$($_.netbios_name0)*'" | select -Expand Enabled`. [Related](https://stackoverflow.com/a/44184818/1630171). – Ansgar Wiechers Nov 03 '17 at 08:58
  • Thanks Ansgar! This works for me. the processing is a little slow though but this is exactly what I've been trying to make work. really appreciate your help. – jcaloy Nov 03 '17 at 10:39
  • If you don't need fuzzy matches change `-like '*$($_.netbios_name0)*'` to `-eq '$($_.netbios_name0)'`. That might speed up processing a little. Alternatively try reading all computer objects (or their `Enabled` property) into a hashtable using their NetBIOS name as the key, then do a hashtable lookup in the calculated property. – Ansgar Wiechers Nov 03 '17 at 10:56
  • Thanks again Ansgar. your suggested alternative looks ok as well. I'll try to hack my way through it. – jcaloy Nov 27 '17 at 07:22

0 Answers0