Cygwin or Powershell

Among those command line workers on Windows, I think Cygwin bash has greater share over Powershell.
I'm one of those and here is my Powershell one-liner I invoke often in bash.

$  powershell -command 'Get-Service' | grep Oracle
Stopped  OATSHelperSvr      Oracle Application Testing Suite He...
Stopped  Oracle Applicat... Oracle Application Testing Suite Ap...
Stopped  OracleASMServic... OracleASMService+ASM

As you can see Powershell is too conservative here and truncates 2 columns too short.


But .. OK. Powershell can do something more intelligent.

$ powershell -command 'Get-Service | Format-Table -AutoSize' | grep Oracle
Stopped OracleASMService+ASM                                 OracleASMServic...
Stopped OracleDBConsoleorcl                                  OracleDBConsole...
Stopped OracleJobSchedulerORCL                               OracleJobSchedu...

Now, Powershell is too tolerant for 2nd column and thus truncates 3rd column too short.
Unfortunately, there seems to be no workaround for mintty which is a default Cygwin tty application.


Now, if you want to do something in the middle, you can give powershell cryptic options.

$ powershell -command 'Get-Service|Format-Table -Property @{Width=7;Align="Left";Expression="Status"},@{Width=32;Expression="Name"},DisplayName' | grep Oracle
Stopped OracleASMService+ASM             OracleASMService+ASM
Stopped OracleVssWriterORCL              Oracle ORCL VSS Writer Service

One needs to use names in 2nd column for command like sc.exe.
As you can see above, for some Oracle Windows service, "Name"(2nd column) and "DisplayName"(3rd) differ.
So, this is something to be aware of if you use sc.exe.
Maybe sc.exe is obsolete but my finger remembers it.





Comments:

You are filtering for Oracle after formatting the table, so format table has to allow for the maximum width of all service names.

If you filter before formatting, the column width only has to allow for the longest Oracle service name.

PS Z:\> get-service | where-object name -like clr* | format-table -autosize

Status Name DisplayName
------ ---- -----------
Stopped clr_optimization_v2.0.50727_32 Microsoft .NET Framework NGEN v2.0.50727_X86
Stopped clr_optimization_v2.0.50727_64 Microsoft .NET Framework NGEN v2.0.50727_X64
Stopped clr_optimization_v4.0.30319_32 Microsoft .NET Framework NGEN v4.0.30319_X86
Stopped clr_optimization_v4.0.30319_64 Microsoft .NET Framework NGEN v4.0.30319_X64

Posted by Alistair Wall on February 19, 2013 at 08:42 PM JST #

Get-Service takes a service name as argument, and it accepts wildcards. Just do

Get-Service *Oracle*

Format-Table can auto-size the columns. Just pass the -AutoSize (you can abbreviate it) switch parameter:

Get-Service *Oracle* | ft -auto

Posted by guest on February 24, 2013 at 02:20 AM JST #

Thanks for the comments.
I always defined the alias below but I will change it.

alias sclist='powershell -command get-service'

Posted by owner on March 19, 2013 at 07:07 PM JST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
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
   
       
Today