However I still I don't like its behavior.
What I want to do is make a suggestion to Microsoft to add this. But before
this I want to show them how to do this. At worst I'll have the feature I
want and I really do think "handing" them code for this will increase my
chances of this getting in to Powershell.
There are two thing I need to do
1) Create a customized type.ps1xml file for
[System.ServiceProcess.ServiceController].
This has been done now either
Get-Service | % {$_.StartType}
or
Get-Service | Format-List *
will display whether each service is demand, auto, ...
2) Create a customized format.ps1xml file for the above type so that the
default "formater" will display this property. This I'm having a hard time
with. There is next to no documentation on this and I see no way to debug or
track down what is going wrong here.
Below are the XML files that I've used for each step
1) type.sc.ps1xml
<Types>
<Type>
<Name>System.ServiceProcess.ServiceController</Name>
<Members>
<ScriptProperty>
<Name>StartType</Name>
<GetScriptBlock>
switch ( ((Get-ItemProperty -Path
HKLM:\system\currentcontrolset\Services\$($this.Name) -Name Start)).Start )
{
0 {"Boot_Start"}
1 {"System_Start"}
2 {"Auto_Start"}
3 {"Demand_Start"}
4 {"Disabled"}
}
</GetScriptBlock>
</ScriptProperty>
</Members>
</Type>
</Types>
That really is all there is to this.
Below is my attempt at customizing what the format of this type should be.
To keep this post as small as possible I'm only showing the XML elment that
I've added. The complete listing for this type is in DotNetTypes.Format.ps1xml
I have modeled this after the system file Certificate.Format.ps1xml which is
the only file that I see using a "scriptblock" in a <ListItem>
While the below file is not generating any errors when processed by
Update-FormatData. I'm not seeing the property StartType which I'm after.
2) <Configuration>
<ViewDefinitions>
<View>
<Name>System.ServiceProcess.ServiceController</Name>
<ViewSelectedBy>
<TypeName>System.ServiceProcess.ServiceController</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
..... add the existing properties here from
<ListItem>
<ScriptBlock>
$_.StartType
</ScriptBlock>
<Label>StartType</Label>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</ViewDefinitions>
</Configuration>
thx
bob
It sounds like you didn't modify the grouping format to include your
new property
Rick I've looked and do see "-GroupingFormat" but I just don't know how to
use this
Kiron,
I did see Append/PrependPath but just didn't understand how either of these
would affect the loading of my format file.
-WhatIf
is worthless and while the Powershell engine will let you easily debug the
<mytype>.ps1xml it won't give you a clue how "debug" or even "printf" type
stuf with the <myformat> siblings.
What I've done is two things which at least gets me past my
mis-understanding on how to create customized format files.
1) As you said I've removed the <scriptblock> in addition I needed to change
the <label> to <propertyname>
2) specified -prepend
ideally I'd like to maintain the same defaults that PS does for this type.
i.e
# without modification this
gsv
#and this with modification are the same
gsv | ft
and
#without modification
gsv | fl *
is more equvialment to
gsv
but I can live with this. At least I have now have something concrete to
show to Microsoft when I try and persuade them to add this modification to
the output of Get-Service
Later when I have more time I'll look into this which is probably a simple
modification of what I have.
thx again to both of you
bob