![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Extending Get-Service with add-member Hi, I am trying to use add-member to get "StartMode" as a property when I run get-service. I am just playing with add-member for now, but would eventually like to add it to my customized types ps1xml file for the [System.ServiceProcess.ServiceController] class I have something that is sort of working but extrememly slow and the output is a little funky PS> $svc = get-service PS> $svc | Add-member ScriptProperty StartMode {get-wmiobject win32_service | where {$_.Name -eq $this.Name} | format-list StartMode} PS> $ $svc | fl Name,StartMode Name : Alerter StartMode : @{startmode=Disabled} Name : ALG StartMode : @{startmode=Manual} So I really have two questions, the first is "Does anyone have any ideas on how to speed this up? I think the WMI Query is killing me here Second question is how can I get the output to look like Name : Alerter StartMode : Disabled rather than StartMode: @{startmode=disabled} Any help would be greatly appreciated Thanks, Andy |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Extending Get-Service with add-member The best improvement I can think of would be to let WMI do the query instead of pulling all the Win32_Service objects out and doing a PSH-style query on them, like so: $svc | add-member ScriptProperty StartMode { get-wmiobject Win32_Service -filter "name='$($this.Name)'" | foreach { $_.StartMode } } Using the -filter property may get the performance to where you need it...it certainly caused a noticeable improvement for me. If it doesn't, then you'll probably need to do some sort of caching or something, probably by combining a ScriptProperty with a NoteProperty or something. If you still feel it's not fast enough after trying the -filter parameter, reply to this and we can talk about how to do it. Note that I pipe the resulting WMI object into foreach and pull out the StartMode property -- that fixes the display issue you're seeing. The reason you're getting the behaviour you are is because format-list actually returns a stream of formatting helper objects (pipe format-list into get-member to see what the deal is with it), which is intended for displaying as a list, not wrapping around the value of one property. Hope this helps. -- Ryan Milligan "ASCHNEIDER146" <aschneider146@gmail.com> wrote in message news:1170788413.331703.63160@m58g2000cwm.googlegroups.com... > Hi, > > I am trying to use add-member to get "StartMode" as a property when I > run get-service. I am just playing with add-member for now, but would > eventually like to add it to my customized types ps1xml file for the > [System.ServiceProcess.ServiceController] class > > I have something that is sort of working but extrememly slow and the > output is a little funky > > PS> $svc = get-service > > PS> $svc | Add-member ScriptProperty StartMode {get-wmiobject > win32_service | where {$_.Name -eq $this.Name} | format-list > StartMode} > > PS> $ $svc | fl Name,StartMode > > > Name : Alerter > StartMode : @{startmode=Disabled} > > Name : ALG > StartMode : @{startmode=Manual} > > So I really have two questions, the first is "Does anyone have any > ideas on how to speed this up? I think the WMI Query is killing me > here > > Second question is how can I get the output to look like > > Name : Alerter > StartMode : Disabled > > rather than StartMode: @{startmode=disabled} > > Any help would be greatly appreciated > > Thanks, > > Andy > |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| extending the C: partition | mattias73 | Vista General | 2 | 02-21-2008 07:31 PM |
| Extending volume | Newfangle9 | General Discussion | 5 | 01-21-2008 01:34 PM |
| Extending partitions | Martin | Vista performance & maintenance | 13 | 07-01-2007 07:14 PM |
| extending a partiton | me_and_you | Vista General | 5 | 01-23-2007 02:49 PM |
| Extending PS through ASP.NET | fixitchris | PowerShell | 1 | 12-01-2006 03:46 PM |