-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Export-ServerInfo.ps1
48 lines (38 loc) · 1.34 KB
/
Export-ServerInfo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<#
.SYNOPSIS
This script retrieves server information from Active Directory and exports it to a CSV file.
.DESCRIPTION
The script queries Active Directory for server objects and extracts the following information:
- Server Name (Hostname)
- IP Address
- FQDN
- Operating System
- Description
The extracted data is then exported to a CSV file.
.PARAMETER OutputPath
The path to the CSV file where the data should be saved.
.EXAMPLE
.\Export-ServerInfo.ps1 -OutputPath "C:\path\to\output.csv"
.NOTES
Make sure the Active Directory module is installed and you have sufficient rights to query AD.
#>
param(
[Parameter(Mandatory=$true)]
[string]$OutputPath
)
# Requires the Active Directory module to be installed
Import-Module ActiveDirectory
# Query AD for servers
$servers = Get-ADComputer -Filter 'OperatingSystem -like "Windows Server*"' -Properties OperatingSystem, Description, DNSHostName, IPv4Address
# Create an object with the desired output for each server
$output = $servers | ForEach-Object {
[PSCustomObject]@{
'ServerName' = $_.Name
'IP Address' = $_.IPv4Address
'FQDN' = $_.DNSHostName
'Operating System' = $_.OperatingSystem
'Description' = $_.Description
}
}
# Export the object to a CSV file
$output | Export-Csv -Path $OutputPath -NoTypeInformation -Delimiter "`t"