Hola Buenas, quería saber si alguien tiene conocimiento de alguna herramienta o método para controlar el tiempo que están conectados los PC´s en una red de dominio. Es decir, seria alguna aplicación que pueda rastrear el dominio y consultar cuanto tiempo lleva levantado un equipo y saber si se utilizan o no los equipos. Muchas gracias
Hola waxlr,
El siguiente es un script Powershell que hacer lo que solicitas y tambien te indica los user ID, en la maquina desde la cual lo ejecutes necesitas tener instalado "Microsoft Remote Server Administration Tools" y obviamente debes rellenar en el script tu informacion.
[CmdletBinding()]
Param (
[int]$Age = 6,
[string]$To = "[email protected]",
[string]$From = "[email protected]",
[string]$SMTPServer = "HostnameOfSMTPrelay"
)
#Set variables
$Then = ((Get-Date).AddDays(-$Age)).Date
$Results = @()
$Header = @"
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #6495ED;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
</style>
"@
#Attempt to load ActiveDirectory module, must have RSAT installed
Try { Import-Module ActiveDirectory -ErrorAction Stop }
Catch { Write-Host "Unable to load Active Directory module, is RSAT installed?" -ForegroundColor Red; Exit }
#Loop through domain computers
ForEach ($Computer in (Get-ADComputer -Filter { OperatingSystem -notlike "*server*" } -Properties OperatingSystem ))
{ Write-Verbose "Attempting to connect to $($Computer.Name)..."
Try {
$Lastboot = Get-WmiObject -ComputerName $Computer.Name -Query "SELECT LastBootUpTime FROM Win32_OperatingSystem" -ErrorAction Stop
}
Catch {
Write-Verbose "Unable to connect to $($Computer.Name)..."
$Results += New-Object PSObject -Property @{
ComputerName = $Computer.Name
User = "Unknown"
LastBoot = "Unknown"
Status = "Unable to connect"
}
Continue
}
Write-Verbose "Connected to $($Computer.Name)..."
$LastBootTime = $Lastboot.ConvertToDateTime($LastBoot.LastBootUpTime)
If ($LastBootTime -lt $Then)
{ Write-Verbose "Hasn't rebooted in over $Age days, rebooting $($Computer.name)..."
$Status = "Rebooted"
Restart-Computer -ComputerName $Computer.Name -WhatIf
}
Else
{ Write-Verbose "$($Computer.Name) last rebooted on $LastBootTime..."
$Status = ""
}
$Results += New-Object PSObject -Property @{
ComputerName = $Computer.Name
User = (Get-WmiObject Win32_ComputerSystem -ComputerName $Computer.Name).Username
LastBoot = $LastBootTime
Status = $Status
}
}
#Build the report
$Body = $Results | Select ComputerName,User,LastBoot,Status | Sort Status,ComputerName | ConvertTo-Html -Head $Header -PreContent "<h2>Reboot report</h2><br>Reboot date: $Then" -PostContent "<br><h3>Run on $(Get-Date)</h3>" | Out-String
#Email the results
Send-MailMessage -To $To -From $From -Subject "Reboot report" -Body $Body -BodyAsHtml -SmtpServer $SMTPServer
Write-Verbose "Script completed, report emailed to $To"
Saludos
Gn0m3