Get-ServerInfo.ps1
19 Sep 2025Description
Purpose
No synopsis provided.
Detailed Description
No detailed description provided.
Usage
No usage examples provided.
Notes
No additional notes.
Script
function Get-ServerInfo {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string[]]$ComputerName
)
process {
$results = @()
foreach ($computer in $ComputerName) {
Write-Verbose "Processing computer: $computer"
$serverInfo = [PSCustomObject]@{
IPAddress = @()
ComputerName = $computer
Type = if ($computer -eq $env:COMPUTERNAME) { "Local" } else { "Remote" }
OS = ""
Services = @()
Tasks = @()
Scripts = @()
Processes = @()
Ports = @()
}
try {
$session = New-CimSession -ComputerName $computer
# IP Addresses
$ipAddresses = Get-CimInstance -CimSession $session -ClassName Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress }
$serverInfo.IPAddress = $ipAddresses.IPAddress
# OS
$os = Get-CimInstance -CimSession $session -ClassName Win32_OperatingSystem
$serverInfo.OS = $os.Caption
# Processes
$processes = Get-ProcessStatus -ComputerName $computer -ProcessName '*'
if ($processes) {
$serverInfo.Processes = $processes | Select-Object -ExpandProperty ProcessName
}
else {
Write-Verbose "No processes found or 'ProcessName' property is missing."
}
# Services
$services = Get-ServiceStatus -ComputerName $computer -ServiceName '*'
if ($services) {
$serverInfo.Services = $services | Select-Object -ExpandProperty DisplayName
}
else {
Write-Verbose "No services found or 'DisplayName' property is missing."
}
# Tasks
$tasks = Get-ScheduledTasks -ComputerName $computer
if ($tasks) {
$serverInfo.Tasks = $tasks | Select-Object -ExpandProperty TaskName
}
else {
Write-Verbose "No tasks found or 'TaskName' property is missing."
}
# Scripts
$scripts = Get-ScheduledScripts -ComputerName $computer -TaskName '*'
if ($scripts) {
$serverInfo.Scripts = $scripts | Select-Object -ExpandProperty TaskName
}
else {
Write-Verbose "No scripts found or 'TaskName' property is missing."
}
# Ports
$ports = Get-NetTCPConnection -CimSession $session | Where-Object { $_.State -eq 'Listen' -and $_.LocalAddress -eq '::' }
if ($ports) {
$serverInfo.Ports = $ports | Select-Object -ExpandProperty LocalPort
}
else {
Write-Verbose "No ports found."
}
$results += $serverInfo
}
catch {
Write-Error "Error processing computer {$computer}: $_"
}
}
$results
}
}
# Example usage
# Get-ServerInfo -ComputerName EXCHANGE01 -Verbose
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.