Enumere todas las funciones de servidor de todos los servidores Windows con PowerShell
¿Está a punto de documentar su entorno de red y sistema operativo? ¿No deseas comprar software de terceros? ¿Quiere enumerar todas las funciones de servidor de todos los servidores de su red? Aquí tienes… con PowerShell, ¿qué más? ?
¿Qué puedo esperar de esta publicación de blog? Echa un vistazo a la imagen de abajo. Si esto es lo que estás buscando, sigue leyendo…
Windows Server admite la instalación de las denominadas funciones y roles. Las características sólo son relevantes localmente. Los roles son roles de red, por ejemplo DHCP, DNS, etc.
Puedes copiar y pegar el código aquí mismo, o puedes descargar el script completo que encontrarás al final de esta publicación y en mi sección de descargas.
Código: recuperar todas las funciones del servidor
Aquí lo tienes. Copie y pegue las líneas en PowerShell ISE o Visual Studio Code y apriete el gatillo, generalmente presione F5.
Por cierto: este script se probó en PowerShell 5.1 y PowerShell 7.
# .SYNOPSIS
# This script collects all installed Server Roles and Features
# from all domain-joined Windows Servers.
# .DESCRIPTION
# The result is displayed in the console and a report will be
# saved in $HOME\ServerRoles"Date".txt.
# The file will open automatically.
# .NOTES
# Run this script with administrative privileges
# on a domain-controller of your domain.
# Supported PowerShell versions: PowerShell 5.1, PowerShell 7
# .AUTHOR
# Patrick Gruenauer | Microsoft MVP PowerShell [2018-2020]
# .WEB
# https://sid-500.com
############################ CODE ###############################
### Retrieving all Servers by Name
$ErrorActionPreference = "SilentlyContinue"
$servers = (Get-ADComputer -Properties operatingsystem `
-Filter 'operatingsystem -like "*server*" -and enabled -eq "true"').Name
### Collection Point
$result = @()
### Ping all Member-Server and if ping is successful run
# Get-WindowsFeature
foreach ($item in $servers) {
$test = Test-Connection $item -Count 1
### Providing PowerShell 7 and 5.1 compatibility in terms of return code
If ($test.Status -eq 'Success' -or $test.StatusCode -eq '0')
{
$roles = Get-WindowsFeature -ComputerName $item |
Where-Object InstallState -EQ 'Installed'
### Write into the collection point
$result += New-Object -TypeName PSObject -Property ([ordered]@{
'Server' = $item
'Roles' = $roles.Name -join "`r`n"
### Escape Character CarriageReturn (`r) + NewLine (`n)
}
)
}
}
### Generating Outputs
# Collecting Point: Console Output
Write-Output $result | Format-Table -Wrap
# Text File Output
$date = Get-Date -Format MM.dd.yyyy
$result | Format-Table -Wrap |
Out-File "$HOME\ServerRoles$date.txt"
Write-Warning "Output file ServerRoles$date.txt generated in $HOME ... Opening file ..."
# Opening File
Start-Process $HOME\"ServerRoles$date.txt"
Como se mencionó anteriormente, copie el código anterior en el editor de PowerShell de su elección o descargue el script en la sección Descargas de mi sitio web.
Para recuperar funciones de servidor en servidores individuales, consulte Windows Server: enumerar todas las funciones y funciones instaladas mediante PowerShell.
¡Diviértete documentando!

