任务计划程序将 PowerShell 输出截断为 80 个字符

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

无论我尝试使用哪种格式或输出方法,我都无法绕过任务调度程序在默认列 80 UGH 处截断输出的能力

我尝试过 Get-CimInstance -computerName $glfServers -Class Win32_OperatingSystem |排序对象 csName |格式表-属性 $csName、$serverStatus、$totalVisibleMemorySize、 $freePhysicalMemory、$memoryUsage、$freeSpaceInPagingFiles、$lastBootTime |外弦宽度 120 |输出文件 'C:\Scripts\OutputFiles\ServerMemory\PyhsMem.txt'

我主要尝试过 Tee-object,这样我就可以将输出同时输出到控制台和文件,结果发现任务调度程序的输出会有所不同。

我尝试了所有常见的疑点 Format-Table -Autosize 和 Out-file,经过几天的搜索,我终于在另一篇 stackoverflow 帖子中找到了答案。

我要发布我的决议,因为这是令人沮丧的几天,看不到任何缓解的迹象。我只是将此添加到我不喜欢 Windows 任务计划程序的另一件事中。

powershell scheduled-tasks truncation
1个回答
0
投票

尤里卡!我终于找到了答案,我非常接近你需要使用 -Stream 来绕过截断。所以最终的工作代码块如下所示:

Get-CimInstance -computerName $glfServers -Class Win32_OperatingSystem |排序对象 csName |格式表-属性 $csName、$serverStatus、$totalVisibleMemorySize、 $freePhysicalMemory、$memoryUsage、$freeSpaceInPagingFiles、$lastBootTime
|输出字符串 -流 - 宽度 120 |输出文件 'C:\Scripts\OutputFiles\ServerMemory\PyhsMem.txt'

© www.soinside.com 2019 - 2024. All rights reserved.