Created
October 31, 2020 10:33
-
-
Save raulunzue/b385090313a6bc19d1b36e8eaa2ed751 to your computer and use it in GitHub Desktop.
Powershell: Comprobar consumo de una aplicación remotamente
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################### | |
## 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