Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Windows 7 Forum Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Extending Get-Service with add-member

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 02-06-2007   #1 (permalink)
ASCHNEIDER146
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 SpecsSystem Spec
Old 02-06-2007   #2 (permalink)
Ryan Milligan
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 SpecsSystem Spec
Closed Thread

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


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51