Hi Alex
Could'nt you just use the Inv_OU_Membership table to get the AD OU information, this information is already inventoried if using the Microsoft Active Directory Import.
If so the SQL query below would get you this information...
SELECT
vc.name [Server Name]
,ou.[Distinguished Name] OU
FROM vcomputer vc
JOIN Inv_OU_Membership ou on ou._ResourceGuid = vc.Guid and ou.IsDirectMember = 1
WHERE vc.[OS Name] like '%server%'
ORDER BY ou.[Distinguished Name]
Original Message:
Sent: 08-27-2020 04:22 PM
From: Alex Campos
Subject: Custom Inventory - List OU
Hello everyone....
I'm trying to create a custom inventory to collect the OU that the server is hosted on AD. I created the data class and working on the script to get the data in.
Here is the script that I wrote. If I run the powershell command it brings the data to me however the problem is that when i run the script via custom inventory, it says sucessfull but the data is not on the data class.
#************************DO NOT EDIT********************************
$nse = new-object -comobject Altiris.AeXNSEvent
$nse.priority = 1
$nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
#************************DO NOT EDIT********************************
#Modify this varaible with the custom data class guid
$objDCInstance = $nse.AddDataClass("{947dd43c-9672-4018-bd3e-e371a1a3a9fc}")
$objDataClass = $nse.AddDataBlock($objDCInstance)
$status = Get-ADComputer $env:computername | Select-Object Name, DistinguishedName
#Add new row of data
$objDataRow = $objDataClass.AddRow()
$objDataRow.SetField(0, $status)
#Send the data
$nse.sendqueued()
Any idea where the problem is? If I use other powershell command, like whoami or hostname...it works fine.
It does not have to be in powershell, this can be done via other way.