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 en...
Joshua_Reynolds
Nov 14, 2023Copper Contributor
if 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.
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.