windows - Sorting in Powershell except few output -


i have multiple services. suppose starts . when execute

get-service a* - display services output starting a.

i sorting complete output except 1 , want on top of list once sorted. using below command.

get-service -displayname a* |sort-object {$_.name -ne 'ak'} 

it listing output in sorted way , ak on top below .

ak ar 

and on . keeping ak on top , sorting others. want same thing 2 services. ak , ar(suppose)- both should in ak , ar order @ top other services need sort. how add in existing code ar.

try -notin operator, can specify array of excludes:

get-service a* | sort-object {$_.name -notin "ak","ar"} 

this way ak , ar service on top of sorted list

edit: v2 simple , easy:

get-service a* | sort-object {"ak","ar" -notcontains $_.name} 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -