ViciousXUSMC Posted May 2, 2019 Share Posted May 2, 2019 (edited) Hey everyone. Looking at how to do a task in where I search for a Computer by key words in it's description. I am using _AD_GetObjectAttribute and can search for the computer name and return the attributes I want, but have no idea how to do sort of the reverse. The computer descriptions get updated with log in and log out timestamps and usernames. If I get a ticket from a user I want to use this to search for what computer they were using. Here is my attempt so far. #Include <AD.au3> _AD_Open() $sResult = _AD_GetObjectAttribute(@ComputerName & "$", "Description") MsgBox(0, "", $sResult) _AD_Close() ;get-adcomputer -filter {name -eq 'redacted'} -properties * ;IPv4Address ;CN ;Description ;Name The fields I want to return would be the Computer Name, Description, and IPv4Address Thanks guys for the help. Edit Looks like what I need is _AD_GetObjectsInOU Now working on that, it requires a lot more context with declaring the proper OU and DC that I am not super familiar with, it will be hard to post much without giving away sensitive information so might have to get generic "help". I sort of have it working, except when I try to ask for IPv4Address it causes an error, and right now I am globally searing the entire AD structure with my filter "objectclass=computer" I can get the computer name and description, but I am not yet filtering the description. I am not sure if I can make my query search more defined, or will just need to do an array search for the results I want. I feel like the query should be defined more to speed up results. Edit2 Ok found out IP Address from Power shell is not in AD. https://www.myotherpcisacloud.com/post/IPv4Address-Attribute-In-Get-ADComputer I also figured out how to filter my search more and return the results I wanted. Pretty sure I got it from here Edited May 2, 2019 by ViciousXUSMC Link to comment Share on other sites More sharing options...
Subz Posted May 2, 2019 Share Posted May 2, 2019 I've created a tool for our helpdesk staff, the condensed version is: #include <AD.au3> _GetCompInfo(@ComputerName) Func _GetCompInfo($_sComputerName) Local $sCompInfo = "Name: " & @TAB & @TAB & $_sComputerName & @CRLF _AD_Open() $sCompInfo &= "Description: " & @TAB & _AD_GetObjectAttribute($_sComputerName & "$", "description") & @CRLF _AD_Close() TCPStartup() $sCompInfo &= "Ip Address: " & @TAB & TCPNameToIP($_sComputerName) & @CRLF TCPShutdown() MsgBox(4096, $_sComputerName & " CompInfo", $sCompInfo) EndFunc Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted May 3, 2019 Author Share Posted May 3, 2019 This is what I ended up with. I might add your TCP stuff to it to pull the IP address. #Include <AD.au3> #Include <Array.au3> #Include <File.au3> $sUserName = InputBox("IIO Automation - Find User Computer", "Input Users Account Name To Search For", "") _AD_Open() ;Open Connection To AD GLOBAL $aObjects[1][1] ;Define The Array To Store Results $aObjects = _AD_GetObjectsInOU("", "(&(objectclass=computer)(description=" & $sUserName & "*))", 2, "sAMAccountName,operatingSystem,Description") ;AD Query Searching for Computers and A Description Starting With X If @error > 0 Then ;If We Have No Results MsgBox(64, "Active Directory", "No Results Found or Bad Query") ;Show Error Message Else _ArrayDisplay($aObjects, "User Known Computers", "1:", 0, Default, "Computer Name|Operating System|Description") ;Show Our Results EndIf _AD_Close() ;Close Connection to AD Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now