Skip to content

Commit d409b32

Browse files
authored
Create Export-ServerInfo.ps1
1 parent 2b16a90 commit d409b32

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Export-ServerInfo.ps1

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

0 commit comments

Comments
 (0)