Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Powershell: Comprobar consumo de una aplicación remotamente
#########################
## RAUL UNZUE - 31102020
## CONSUMO APP - ELBLOGDENEGU
#########################
## LISTA DE SERVIDORES
$listaservers= (Get-Content C:\Users\runzue\Documents\SCRIPTS\servers.txt)
## CREDENCIALES DE CONEXION
$passwd = convertto-securestring -AsPlainText -Force -String "NUESTRAPASSWORD"
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist ('DOMINIO\USUARIO',$passwd)
## CONEXION A SERVIDORES
foreach ($servidor in $listaservers) {
$dia=get-date -Format "dd-MM-yyyy"
$hora=Get-Date -Format "HH:mm:ss"
$processname= 'lync'
$r = Invoke-Command -ComputerName $servidor -Credential $cred -ScriptBlock {get-process -Name $processname -IncludeUserName | Select-Object Name,Username,CPU,WorkingSet,PrivateMemorySize}
$s = Invoke-Command -ComputerName $servidor -Credential $cred -ScriptBlock {Get-WmiObject Win32_PerfRawData_PerfProc_Process -filter "Name <> '_Total' and Name <> 'Idle'" | Sort PercentProcessorTime -descending | Select -first 5 Name,@{Name="PercentProcessorTime";Expression={($_.PercentProcessorTime/100000/100)/60}},IDProcess,PSComputername | Where-Object { $processname -contains $_.Name}}
if ($r -eq $null)
{
Write-Output "$dia - $hora - $servidor - Buscando procesos APP Lync" >> C:\Users\runzue\Documents\PROYECTOS\SCRIPTS\lync.txt
Write-Output "No podemos conectar con $servidor" >> C:\Users\runzue\Documents\SCRIPTS\lync.txt
}
else
{
Write-Output "$dia - $hora - $servidor - Buscando procesos APP Lync" >> C:\Users\runzue\Documents\SCRIPTS\lync.txt
$resultado = $r | Format-Table Name,Username,@{l="CPU"; e={$_.cpu / 1024}},@{l="Private Memory (MB)"; e={$_.privatememorysize / 1mb}},@{l="Working Set (MB)"; e={$_.WorkingSet / 1mb}} -AutoSize
$resultado2 = $s | Format-Table Name, @{n='Mem (MB)';e={'{0:N0}' -f (($_.Group|Measure-Object WorkingSet -Sum).Sum / 1MB)};a='right'} -AutoSize
Write-Output "APP Lync POR USUARIO" >> C:\Users\runzue\Documents\PROYECTOS\SCRIPTS\lync.txt
$resultado >> C:\Users\runzue\Documents\SCRIPTS\lync.txt
Write-Output "APP Lync POR SERVIDOR" >> C:\Users\runzue\Documents\PROYECTOS\SCRIPTS\lync.txt
$resultado2 >> C:\Users\runzue\Documents\SCRIPTS\lync.txt
}
}
Get-Content -Path C:\Users\runzue\Documents\SCRIPTS\lync.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment