{"id":60,"date":"2018-05-04T11:08:38","date_gmt":"2018-05-04T10:08:38","guid":{"rendered":"http:\/\/banfi.co.uk\/blog\/?p=60"},"modified":"2018-05-04T11:09:55","modified_gmt":"2018-05-04T10:09:55","slug":"export-active-directory-computers-to-csv","status":"publish","type":"post","link":"https:\/\/banfi.co.uk\/blog\/2018\/05\/export-active-directory-computers-to-csv\/","title":{"rendered":"Export Active Directory Computers to CSV"},"content":{"rendered":"<p>Quick power shell to run on a Domain Controller to export all Computers with last logged in time to a CSV file located in C:\\Temp\\ExportADComputers<br \/>\nSome code was based on a Technet example but improved for my use to get Extended details out.<\/p>\n<p>Example of CSV output<\/p>\n<p>name\twhenCreated\tIPv4Address\tOperatingSystem\tOperatingSystemVersion\tLastLogonDate\tEnabled<br \/>\nComputer-001\t09\/01\/2017 18:05\t10.x.x.x\tWindows 10 Pro\t10.0 (14393)\t09\/01\/2017 18:08\tTRUE<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n###########################################################\r\n# AUTHOR  : Darren Banfi\r\n# CREATED : 11-04-2018 \r\n# UPDATED : \r\n# COMMENT : This script exports Active Directory computers\r\n#           to a a csv file.\r\n###########################################################\r\n\r\n#1.0 - First Release\r\n\r\n\r\n# Created Folder automatically\r\nNew-Item -ItemType directory -Path C:\\Temp\\ExportADComputers\r\n\r\n#Define location of my script variable\r\n#the -parent switch returns one directory lower from directory defined. \r\n#below will return up to ImportADUsers folder \r\n#and since my files are located here it will find it.\r\n#It failes withpout appending &quot;*.*&quot; at the end\r\n\r\n$path = Split-Path -parent &quot;c:\\temp\\ExportADComputers\\*.*&quot;\r\n\r\n#Create a variable for the date stamp in the log file\r\n\r\n$LogDate = get-date -f yyyyMMddhhmm\r\n\r\n#Define CSV and log file location variables\r\n#they have to be on the same location as the script\r\n\r\n$csvfile = $path + &quot;\\ALLADComputers_$logDate.csv&quot;\r\n\r\n#import the ActiveDirectory Module\r\n\r\nImport-Module ActiveDirectory\r\n\r\n\r\n#Sets the OU to do the base search for all Computer accounts, change as required.\r\n\r\n$OUpaths = GET-ADDomain | Select-Object -ExpandProperty ComputersContainer\r\n\r\n#Get Admin accountb credential\r\n\r\n$GetAdminact = Get-Credential\r\n\r\n# loop though the array of OUs, adding the computers to a list ('Object' really)\r\nforeach ($iOUpath in $OUpaths)\r\n    {\r\n        ($objComputers += Get-ADComputer -SearchBase $iOUpath -Properties * -Filter *)    #You might need to refine the query witha 'Filter' depending on your AD structure\r\n    }\r\n\r\n\r\n#Export CSV report\r\n\r\n$objComputers | Select name, whenCreated,  IPv4Address, OperatingSystem, OperatingSystemVersion, LastLogonDate, Enabled | Export-Csv -LiteralPath  $csvfile -NoTypeInformation\r\n\r\n#Open the folder on screen\r\nii C:\\Temp\\ExportADComputers\r\n\r\n&quot;Done&quot;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Quick power shell to run on a Domain Controller to export all Computers with last logged in time to a CSV file located in C:\\Temp\\ExportADComputers Some code was based on a Technet example but improved for my use to get Extended details out. Example of CSV output name whenCreated IPv4Address OperatingSystem OperatingSystemVersion LastLogonDate Enabled Computer-001 &hellip; <a href=\"https:\/\/banfi.co.uk\/blog\/2018\/05\/export-active-directory-computers-to-csv\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Export Active Directory Computers to CSV<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[15,11],"tags":[],"class_list":["post-60","post","type-post","status-publish","format-standard","hentry","category-audit","category-powershell"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/banfi.co.uk\/blog\/wp-json\/wp\/v2\/posts\/60","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/banfi.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/banfi.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/banfi.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/banfi.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=60"}],"version-history":[{"count":3,"href":"https:\/\/banfi.co.uk\/blog\/wp-json\/wp\/v2\/posts\/60\/revisions"}],"predecessor-version":[{"id":63,"href":"https:\/\/banfi.co.uk\/blog\/wp-json\/wp\/v2\/posts\/60\/revisions\/63"}],"wp:attachment":[{"href":"https:\/\/banfi.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=60"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/banfi.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=60"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/banfi.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}