View windows with cygwin

I am trying to port some of my routine shell operations from powershell to cygwin, mainly as a training exercise, but also because I'm really starting to like some of the linux flavor tools. One thing I'm still trying to solve is to list / process the Windows services. Powershell had very convenient tools for this, for example:

stop-service [pattern] start-service [pattern] gsv (or get-service) [pattern] 

I've been working with a lot of user services lately, and I would not want to switch to PowerShell to do this in my normal workflow. Has anyone worked this out? A few google attempts at this have been drowned out by a lot of things on how to deal with cygwin working as a service.

Any help / advice is greatly appreciated ...

+6
source share
2 answers

How about invoking powershell commands from cygwin?

 cmd /c '%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe' -Command "gsv" 

EDIT . And a more general solution would be to create a powershell.sh script that contains:

 #!/bin/bash set -e set -u cmd /c '%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe' -Command " $@ " 

After that, you can run: ./powershell.sh gsv or any commands you need.

+6
source

How about calling powershell from inside cygwin without calling CMD.exe?

Use powershell bash script - as a wrapper for powershell.exe or as a she-bang in .ps1 script. See https://bitbucket.org/jbianchi/powershell

0
source

Source: https://habr.com/ru/post/914133/


All Articles