简体   繁体   English

在 PowerShell 列表中创建一个 txt 文件,列出所有正在运行的服务

[英]create a txt file in PowerShell list of all running services

I am trying to create a txt file in PowerShell that provides a list of services that are running.我正在尝试在 PowerShell 中创建一个 txt 文件,该文件提供正在运行的服务列表。 This what I came up with but it keeps on giving me an error message that says its not valid.这是我想出的,但它一直给我一条错误消息,说它无效。

Get-Service | Export-txt -path "C:\Windows\Temp\services.txt"

Get-Service | where {$_.Status -eq "Running"} | Export-txt -path "C:\Windows\Temp\services.txt"

There is no commandlet called Export-txt .没有名为Export-txt的命令行开关。

One option is to use Out-File .一种选择是使用Out-File It uses -FilePath as a parameter (or no named flag).它使用-FilePath作为参数(或没有命名标志)。

Get-Service | Out-File -FilePath "C:\Windows\Temp\services.txt"

There is no cmdlet by the name of Export-txt .没有名为Export-txt的 cmdlet。 To get a list of cmdlets you can use, you can think logically and apply that to Get-Command .要获取可以使用的 cmdlet 列表,您可以进行逻辑思考并将其应用于Get-Command Running Get-Command will get you a list of all available cmdlets you may use in accordance with your Posh version.运行Get-Command将为您提供根据您的 Posh 版本可以使用的所有可用 cmdlet 的列表。

Get-Command *out* returns a list of cmdlets you can send out to something. Get-Command *out*返回您可以发送给某物的 cmdlet 列表。 Same logic applies to Get-Command "Export*" .相同的逻辑适用于Get-Command "Export*"

#This gets you all services
Get-Service | Out-File "C:\Windows\Temp\services.txt"

#This gets you only running services
Get-Service | where {$_.Status -eq "Running"} | Out-File "C:\Tmp.txt"

Use Get-Help Out-File to see how the cmdlet is used and what parameters it accepts.使用Get-Help Out-File查看 cmdlet 的使用方式以及它接受的参数。 It also lists examples you can use.它还列出了您可以使用的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM