![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Assignment Help I am working on an assignment for school and i need to create several scripts and im stuck with a few. First: One needs to list the process and the companies who published the program in descending order of number of processes associated with that company, and allow the user to choose a company in order to bring up a google search page about it. Eg: 1 Microsoft Corporation 3 VMware, Inc. 4 GRISOFT, s.r.o. 6 COMODO 7 Apple Inc. I use the following command to list the process in order, but i dont know how to select the actual company it self to display in google. $comp= Get-Process | select company | sort company -unique | sort count -Descending for ($ii=0; $ii -lt $comp.length; $ii++) { Write-Host "$ii"$comp[$ii] } Second: List the top 10 processes in terms of CPU time used, showing name and a graphical representation of the CPU time used, using the * character across the screen. Eg: firefox .............................................................................................................. services ................................................. explorer ............................................. powershell ............................................ Again i have worked out a little bit, but i cant convert the CPU time into the "*" character. This is the code i am using, but i get an error Get-Process | sort -Descending cpu | select -First 10 name, cpu | ForEach-Object { $_.name "*" [int]$_.cpu} Thanks you for looking taking the time to look at my enquiry. I am open for any suggestions. Cheers |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Assignment Help Quote: > Second: > List the top 10 processes in terms of CPU time used, showing name and a > graphical representation of the CPU time used, using the * character across > the screen. PS > gps|sort -desc cpu|select -first 10 name,cpu| ` ft name,cpu,@{l="Ticks";e={"*"*$_.cpu}} Name CPU Ticks ---- --- ----- naPrdMgr 26.125 ************************** FrameworkService 19.265625 ******************* explorer 15.921875 **************** svchost 15.921875 **************** System 15.875 **************** Mcshield 13.703125 ************** AttensaEngine 9.53125 ********** services 8.6875 ********* vmware-authd 8.09375 ******** VsTskMgr 6.453125 ****** Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Assignment Help Quote: > One needs to list the process and the companies who published the program in > descending order of number of processes associated with that company, and > allow the user to choose a company in order to bring up a google search page > about it. engine" earlier in this same newsgroup. Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Assignment Help Get-Process | Sort-Object CPU -Descending | Select-Object -First 10 | ForEach-Object { $time = ([int]$_.TotalProcessorTime.TotalSeconds)/10 $stars = "*" * $time "{0,15} {1,-50}" -f $_.Name, $stars } CPU is actually a script property for Totalprocessor time which is a timespan object Take the toatl seconds and divide by 10 to give a viewable display use a formatted string to show the name and the graphical representation -- Richard Siddaway All scripts are supplied "as is" and with no warranty PowerShell MVP Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "Marco Shaw [MVP]" wrote: Quote: > Quote: > > Second: > > List the top 10 processes in terms of CPU time used, showing name and a > > graphical representation of the CPU time used, using the * character across > > the screen. > Does this work for you or you need the exact format you provided: > > PS > gps|sort -desc cpu|select -first 10 name,cpu| ` > ft name,cpu,@{l="Ticks";e={"*"*$_.cpu}} > > Name > CPU Ticks > ---- > --- ----- > naPrdMgr > 26.125 ************************** > FrameworkService > 19.265625 ******************* > explorer > 15.921875 **************** > svchost > 15.921875 **************** > System > 15.875 **************** > Mcshield > 13.703125 ************** > AttensaEngine > 9.53125 ********** > services > 8.6875 ********* > vmware-authd > 8.09375 ******** > VsTskMgr > 6.453125 ****** > > Marco > > > -- > Microsoft MVP - Windows PowerShell > http://www.microsoft.com/mvp > > PowerGadgets MVP > http://www.powergadgets.com/mvp > > Blog: > http://marcoshaw.blogspot.com > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Assignment Help Hi Arda, For your first assignment: $procs = gps | group company | sort count -desc -unique | where {$_.name} write-host "Choose company to display in Google:`n" for($i=0;$i -lt $procs.length; $i++){"$($i+1)." + $procs[$i].name} $c = read-host "`nYour choice number" $url = "http://www.google.co.il/search?q=" + $procs[$c-1].name $ie = new-object -com internetExplorer.application $ie.visible=$true $ie.navigate($url) For the second, take a look at Kiron's solution, here: http://www.microsoft.com/communities...&cr=&sloc=&p=1 --- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: > I am working on an assignment for school and i need to create several > scripts > and im stuck with a few. > First: > One needs to list the process and the companies who published the > program in > descending order of number of processes associated with that company, > and > allow the user to choose a company in order to bring up a google > search page > about it. > Eg: > 1 Microsoft Corporation > 3 VMware, Inc. > 4 GRISOFT, s.r.o. > 6 COMODO > 7 Apple Inc. > I use the following command to list the process in order, but i dont > know how to select the actual company it self to display in google. > > $comp= Get-Process | select company | sort company -unique | sort > count > -Descending > for ($ii=0; $ii -lt $comp.length; $ii++) > { > Write-Host "$ii"$comp[$ii] > } > Second: > List the top 10 processes in terms of CPU time used, showing name and > a > graphical representation of the CPU time used, using the * character > across > the screen. > Eg: > > firefox > > ...................................................................... > ....................................... > > services > > ................................................ > > explorer > > ............................................ > > powershell > > ........................................... > > Again i have worked out a little bit, but i cant convert the CPU time > into the "*" character. This is the code i am using, but i get an > error Get-Process | sort -Descending cpu | select -First 10 name, cpu > | ForEach-Object { $_.name "*" [int]$_.cpu} > > Thanks you for looking taking the time to look at my enquiry. I am > open for any suggestions. Cheers > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Assignment Help On Jun 9, 12:50*am, Arda <A...@xxxxxx> wrote: Quote: > I am working on an assignment for school and i need to create several scripts > and im stuck with a few. > First: > One needs to list the process and the companies who published the program in > descending order of number of processes associated with that company, and > allow the user to choose a company in order to bring up a google search page > about it. > > Eg: > 1 Microsoft Corporation > 3 VMware, Inc. > 4 GRISOFT, s.r.o. > 6 COMODO > 7 Apple Inc. > > I use the following command to list the process in order, but i dont know > how to select the actual company it self to display in google. > > $comp= Get-Process | select company | sort company -unique | sort count > -Descending > for ($ii=0; $ii -lt $comp.length; $ii++) > { > * *Write-Host "$ii"$comp[$ii] > > } > easier to create Write-Host ('{0,2}: {1}' -f ++$ii,$comp.company) Your earlier question about integer validation seems to indicate you can already get the entry number although some additional criteria seems needed. while ($($e=read-host 'Select an entry'; $e -notmatch "^\d+$" -or $e -lt 0 -or $e -gt $comp.count)) {"Sorry invalid entry. Must be between 1 and $($comp.length)"} |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| IP assignment | Virtual Server | |||
| lab assignment | Vista General | |||
| CTRL key (re)assignment | Vista hardware & devices | |||
| Drive letter assignment | Vista General | |||
| Variable assignment gone bad | PowerShell | |||