PowerShell详细参数

问题描述 投票:0回答:1

我对详细参数有一些疑问。示例脚本:

try {
    New-Item -Path "C:\Test.txt" -ItemType "File" -ErrorAction Stop -Verbose
}
catch {
    Write-Host $Error[0]
}

输出:

VERBOSE: Execute the "Create file" operation for the target "Target: C:\Test.txt".
Access to the path "C: \ Test.txt" was denied.

如何将详细消息保存在变量中?

是否有可能在将其保存到日志文件(添加日期和时间)之前,编辑由PowerShell自动生成的详细消息?示例脚本(不起作用):

try {
    New-Item -Path "C:\Test.txt" -ItemType "File" -ErrorAction Stop -Verbose *> $LogFile
}
catch {
    Write-Host $Error[0]
}

与使用参数verbose而不需要手动写入相比,是否有更好的建议来编写“成功”日志文件?

谢谢!

我对详细参数有一些疑问。示例脚本:尝试{New-Item -Path“ C:\ Test.txt” -ItemType“ File” -ErrorAction Stop -Verbose} catch {Write-Host $ Error [0]}输出:...

powershell logfile verbose
1个回答
0
投票
如果将Verbose流合并为标准输出流(4>&1),则可以将详细输出分配给变量:
© www.soinside.com 2019 - 2024. All rights reserved.