PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 17, 2022

[FIXED] How get output to a variable

 August 17, 2022     output, powershell     No comments   

Issue

I have a simple powershell script

$proc = Get-Process -id 412
$proc

it's return such output

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName                                                                                                                                                                
-------  ------    -----      -----     ------     --  -- -----------                                                                                                                                                                
    434      26    65768     109144       6,42    412   1 browser

how can i get this output to a variable so i can use it somewhere else in script?

I tryed to use it likes this

$proc = Get-Process -id 412
Write-Host $proc

but it gives me not same output as $proc is a instance of "System.Diagnostics.Process" class

System.Diagnostics.Process (browser)

Solution

It depends on exactly what you mean. $proc is an object with properties. If you do $x = $proc | out-string then $x will be the string representation of the default view. However in terms of using it later you might like to do write-host $proc.Handles $proc.NPM $proc.PM $proc.WS $proc.CPU $proc.id $proc.SI $proc.ProcessName to access each of the individual elements.



Answered By - Mark Elvers
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing