Hey guys...
I was wondering if someone could help me with a script I have. What I am trying to do is import a csv file that has 2 columns (Server and Process), each server has different process that I want to check. So I want the script to import the file and read each line, connect to that server and check and see if the processes are running for that particular server then continue with the next one (which will be a different server and different processes).With this i want to capture the percentage of each process and how much mem it is taking (like you see in task manager) I can't seem to get it to work, can someone help me?
Thanks in advance..
I was wondering if someone could help me with a script I have. What I am trying to do is import a csv file that has 2 columns (Server and Process), each server has different process that I want to check. So I want the script to import the file and read each line, connect to that server and check and see if the processes are running for that particular server then continue with the next one (which will be a different server and different processes).With this i want to capture the percentage of each process and how much mem it is taking (like you see in task manager) I can't seem to get it to work, can someone help me?
Code:
[COLOR=blue]
$path = "C:\CMonitor.csv"
$csv = Import-csv -path $path
$ProcBefore=Get-Process -computername $line.Server -Name $line.Processes
$usage="{0:P2}" -f (1-(($p.workingset)/($z[0].workingset)))
# Take a snapshot of running processes
Write-Host "Sleeping..."
sleep -Seconds 10
foreach ($p in $ProcBefore) {
$procAfter | where {$_.id -eq $p.id} -OutVariable z | Out-Null
if (($z[0].workingset)-($p.workingset) -gt 0 ) {
$usage="{0:P2}" -f (1-(($p.workingset)/($z[0].workingset)))
# defined a variable for later use with write-host
$color="RED"
}
Else
{
# there was no difference so set default variables
$usage="0 %"
$color="WHITE"
}
foreach($line in $csv)
{
$ProcBefore #Get-Process -computername $line.Server -Name $line.Processes
}
# write the results to the screen
Write-Host -ForegroundColor $color ($p.id) ($p.name)
Write-Host -ForegroundColor $color BEFORE: ($p.workingset) AFTER: ($z[0].workingset)
Write-Host -ForegroundColor $color Usage: $usage
}
[/color]
Thanks in advance..