95 lines
2.8 KiB
PowerShell
95 lines
2.8 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Sonda de Relevamiento para Nodos Windows (Compatible con Agente srv-NS8)
|
|
Versión: 1.0.0
|
|
Autor: Ricardo MONLA (Generado por Agente)
|
|
|
|
.DESCRIPTION
|
|
Recolecta información de Hardware, Red, Sistema Operativo y Servicios.
|
|
Genera un objeto JSON compatible con la Ontología del proyecto.
|
|
|
|
.EXAMPLE
|
|
.\sonda_windows.ps1
|
|
#>
|
|
|
|
$ErrorActionPreference = "SilentlyContinue"
|
|
|
|
# --- 1. Sistema Operativo ---
|
|
$os = Get-CimInstance Win32_OperatingSystem
|
|
$cs = Get-CimInstance Win32_ComputerSystem
|
|
|
|
# --- 2. Hardware: CPU ---
|
|
$cpu = Get-CimInstance Win32_Processor | Select-Object -First 1
|
|
$cpuName = $cpu.Name.Trim()
|
|
$cores = $cpu.NumberOfCores
|
|
$threads = $cpu.NumberOfLogicalProcessors
|
|
|
|
# --- 3. Hardware: RAM ---
|
|
$ramBytes = $cs.TotalPhysicalMemory
|
|
$ramGB = [Math]::Round($ramBytes / 1GB, 2)
|
|
|
|
# --- 4. Hardware: Discos ---
|
|
$disks = Get-CimInstance Win32_LogicalDisk | Where-Object { $_.DriveType -eq 3 } | ForEach-Object {
|
|
@{
|
|
id = $_.DeviceID
|
|
size_gb = [Math]::Round($_.Size / 1GB, 2)
|
|
used_gb = [Math]::Round(($_.Size - $_.FreeSpace) / 1GB, 2)
|
|
free_gb = [Math]::Round($_.FreeSpace / 1GB, 2)
|
|
fs_type = $_.FileSystem
|
|
mount_point = $_.DeviceID
|
|
}
|
|
}
|
|
|
|
# --- 5. Red ---
|
|
$netAdapters = Get-NetAdapter | Where-Object { $_.Status -eq 'Up' } | ForEach-Object {
|
|
$ipInfo = Get-NetIPAddress -InterfaceAlias $_.Name -AddressFamily IPv4 | Select-Object -First 1
|
|
@{
|
|
interface = $_.Name
|
|
mac = $_.MacAddress
|
|
ip = if ($ipInfo) { $ipInfo.IPAddress } else { "N/A" }
|
|
state = "UP"
|
|
speed_mbps = [Math]::Round($_.LinkSpeed / 1MB, 0)
|
|
}
|
|
}
|
|
|
|
# --- 6. Software Detectado (Servicios Clave) ---
|
|
$servicesToCheck = @("Tailscale", "RustDesk", "AnyDesk", "TeamViewer", "ssh-agent", "sshd")
|
|
$detectedServices = Get-Service | Where-Object { $servicesToCheck -contains $_.Name -or $servicesToCheck -contains $_.DisplayName } | ForEach-Object {
|
|
@{
|
|
name = $_.Name
|
|
status = $_.Status.ToString()
|
|
startup = $_.StartType.ToString()
|
|
}
|
|
}
|
|
|
|
# --- 7. Construcción del JSON ---
|
|
$sondaData = @{
|
|
timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
|
|
node = @{
|
|
hostname = $cs.DNSHostName
|
|
os = "$($os.Caption) ($($os.OSArchitecture))"
|
|
version = $os.Version
|
|
domain = $cs.Domain
|
|
model = $cs.Model
|
|
}
|
|
hardware = @{
|
|
cpu = @{
|
|
model = $cpuName
|
|
cores = $cores
|
|
threads = $threads
|
|
}
|
|
ram_gb = $ramGB
|
|
disks = $disks
|
|
}
|
|
network = $netAdapters
|
|
services = $detectedServices
|
|
meta = @{
|
|
agent_version = "1.0.0-win"
|
|
type = "probe_windows"
|
|
}
|
|
}
|
|
|
|
# --- 8. Salida ---
|
|
$jsonOutput = $sondaData | ConvertTo-Json -Depth 5
|
|
Write-Output $jsonOutput
|