Forum Discussion
darshan8822
Sep 13, 2021Copper Contributor
How to get hostname details from AD
Hi, I need a PS script to extract the below details from AD. hostname, createddate,ip address,createdby,bitlocker status,OU detials,USB details.
SteveMacNZ
Sep 13, 2021Iron Contributor
as farismalaeb said not all of this information is stored in AD (depending on your configuration bitlocker keys may be stored in AD) you could cobble together a script to collect this information with a combination of Get-ADUser cmdlet, Ping/NSLookup, Get-WMIObject / PS remoting. depending on your firewall configurations.
Using a for loop process each AD object collect the various AD attributes storing them in different variables, then attempt a ping of the device - using an if statement to complete the Get-WmiObject lookups if the device is online (would also include some logic to check that IP address returned is the actual host you are looking for (since DNS can get stale leading to incorrect data) then write all the variable containing the collection information to a CVS file (using append) reset all the defined variables then move to the next device.
Using a for loop process each AD object collect the various AD attributes storing them in different variables, then attempt a ping of the device - using an if statement to complete the Get-WmiObject lookups if the device is online (would also include some logic to check that IP address returned is the actual host you are looking for (since DNS can get stale leading to incorrect data) then write all the variable containing the collection information to a CVS file (using append) reset all the defined variables then move to the next device.