Forum Discussion
Bill_Tillman
Nov 09, 2023Copper Contributor
AD Script to Get Users and Computer Information
I could a little assistance with how to properly syntax a PowerShell script to gather information on the users and their computers in our Windows 2022 server network. I'd like to get a list of the enabled users, their IP addresses, their email addresses, their operating system, their host name and maybe a few other items. I have figured most of it out but the trouble I'm having is that I need Get-ADUser and Get-ADComputer commands to get all this in a single list. I'm not even sure this can be done as I can't see how to link the two commands to get all the items needed for my inventory list.
- Joshua_ReynoldsCopper Contributorif you have found a way to link the information for the user and the computer and you have it in the singular (be it via a foreach loop or not) then you could look to something as Harm_Veenstra has suggested with PSCustomObject
one of the ways I script it is:
$table = @()
$userdetails = get-aduser command you are using
$computerdetails - get-adcomputer command you are using
$table += new-object -type psobject -Property @{
User = $userdetails.name
Computer= $computerdetails.name
UserEnabled = $userdetails.enabled
}
Then once you've added in all the rows you wish into the table the variable will hold everything for you. Please note $table = @() is run only once to set the table up initially if that line exists after you've entered a row it will wipe the table. - For example, you can put them in a PSCustomObject, but what do you have now? Could you show us?