powershell 输出记录到文件

powershell 输出记录到文件

我正在尝试使用命令让https://docs.microsoft.com/en-us/powershell/scripting/samples/redirecting-data-with-out---cmdlets?view=powershell-7 如下

    PS C:\WINDOWS\system32> Get-Process | Format-List | Out-Host -Paging | OutFile -FilePath C:\Users\didja\koera dutata\forum questions\out.txt
    OutFile : The term 'OutFile' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
    the path is correct and try again.
    At line:1 char:48
    + Get-Process | Format-List | Out-Host -Paging | OutFile -FilePath C:\U ...
    +                                                ~~~~~~~
        + CategoryInfo          : ObjectNotFound: (OutFile:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

PS C:\WINDOWS\system32> Get-Process | Format-List | Out-Host -Paging | OutFile -FilePath C:\Users\didja\koera dutata\forum questions\out.txt
OutFile : The term 'OutFile' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
At line:1 char:48
+ Get-Process | Format-List | Out-Host -Paging | OutFile -FilePath C:\U ...
+                                                ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (OutFile:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    PS C:\WINDOWS\system32> Get-Process | Format-List | Out-Host -Paging | OutFile -FilePath "C:\Users\didja\koera dutata\forum questions\out.txt"
    OutFile : The term 'OutFile' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
    the path is correct and try again.
    At line:1 char:48
    + Get-Process | Format-List | Out-Host -Paging | OutFile -FilePath "C:\ ...
    +                                                ~~~~~~~
        + CategoryInfo          : ObjectNotFound: (OutFile:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

PS C:\WINDOWS\system32> Get-Process |  Out-Host -Paging | OutFile -FilePath "C:\Users\didja\koera dutata\forum questions\out.txt"
OutFile : The term 'OutFile' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
At line:1 char:35
+ Get-Process |  Out-Host -Paging | OutFile -FilePath "C:\Users\Danda K ...
+                                   ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (OutFile:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\WINDOWS\system32> Get-Process |  OutFile -FilePath "C:\Users\didja\koera dutata\forum questions\out.txt"
OutFile : The term 'OutFile' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
At line:1 char:16
+ Get-Process |  OutFile -FilePath "C:\Users\didja\koera duta ...
+                ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (OutFile:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

上述用法有何错误?

答案1

out-hostout-file是互斥的。您需要使用其中一个。

答案2

我认为你正在尝试制作 T 恤。以下是你需要的内容:

Get-Process | Tee-Object "FilePath" | more

相关内容