I'am developing a script for one of our clients, they are using some accounting apps that need to be closed on the terminal server in order to update the apps from time to time.
I've came up with a script that will ask what the user want to do and then show him the correct out put, the thing is, that my out put looks like a hashtable when, and I don't know what to do in order to group the output correctly and organize it by the process name
here is a part of the code:
$apps = Get-Process CpaPlus,ShklMnNT,HonProj,hisMain,hazharon -IncludeUserName
$apps|Group-Object ProcessName
the output looks like that:
----- ---- -----
4 CpaPlus {@{UserName=bla\user; ProcessName=CpaPlus}, @{UserName=bla\user; ProcessName=CpaPlus}, @{UserName=bla\user; ProcessName=CpaP...
2 hisMain {@{UserName=bla\user; ProcessName=hisMain}, @{UserName=bla\user; ProcessName=hisMain}}
disaired output:
count processname user
---- ---------- ---
4 cpaplus michael
thanks a lot for your help.
If you want to group on both ProcessName
and UserName
, you'll have to tell Group-Object
to do both:
$ProcessByUser = $apps |Group-Object ProcessName,UserName
We can then use Select-Object
to grab the relevant properties from one of the existing objects:
$ProcessByUser |Select-Object Count,@{Name='ProcessName';Expression={$_.Groups[0].ProcessName}},@{Name='UserName';Expression={$_.Groups[0].UserName}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.