Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views1 page

Server Details

The document is a PowerShell script that loads the Active Directory module and retrieves all computers with 'Server' in their operating system. It collects details such as name, DNS hostname, operating system, IPv4 address, last logon date, domain, and organizational unit into a custom object array. Finally, it displays the server details in a formatted table and includes an optional line to export the data to a CSV file.

Uploaded by

vslrinfotech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Server Details

The document is a PowerShell script that loads the Active Directory module and retrieves all computers with 'Server' in their operating system. It collects details such as name, DNS hostname, operating system, IPv4 address, last logon date, domain, and organizational unit into a custom object array. Finally, it displays the server details in a formatted table and includes an optional line to export the data to a CSV file.

Uploaded by

vslrinfotech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

# Load AD module

Import-Module ActiveDirectory

# Get all computers with OperatingSystem containing "Server"


$servers = Get-ADComputer -Filter {OperatingSystem -like "*Server*"} -Property
Name, OperatingSystem, IPv4Address, LastLogonDate, DNSHostName, DistinguishedName

# Create an array to hold server details


$serverDetails = @()

foreach ($server in $servers) {


$details = [PSCustomObject]@{
Name = $server.Name
DNSHostName = $server.DNSHostName
OperatingSystem = $server.OperatingSystem
IPv4Address = $server.IPv4Address
LastLogon = $server.LastLogonDate
Domain = ($server.DistinguishedName -split ',')[1] -replace '^DC='
OU = ($server.DistinguishedName -split ',OU=')[1]
}
$serverDetails += $details
}

# Display in table format


$serverDetails | Sort-Object Name | Format-Table -AutoSize

# Optional: Export to CSV


# $serverDetails | Export-Csv -Path "AD_Servers_Report.csv" -NoTypeInformation -
Encoding UTF8

You might also like