Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Azure管道中运行Powershell命令输出文件会剪切行_Powershell_Azure Pipelines - Fatal编程技术网

在Azure管道中运行Powershell命令输出文件会剪切行

在Azure管道中运行Powershell命令输出文件会剪切行,powershell,azure-pipelines,Powershell,Azure Pipelines,作为CI管道的一部分,我需要生成存储库中所有文件的列表,包括它们的某些属性,并将其归档到文件中。我使用的命令是: Get-ChildItem $Path -File -Recurse | Select-Object -Property LastWriteTime, @ { label = "Size(KB)" expr = { [string]::Format("{0:0.00}", $_.Length/1KB) } }, FullName

作为CI管道的一部分,我需要生成存储库中所有文件的列表,包括它们的某些属性,并将其归档到文件中。我使用的命令是:

Get-ChildItem $Path -File -Recurse | Select-Object -Property LastWriteTime, @
 {
  label = "Size(KB)"
  expr = {  [string]::Format("{0:0.00}", $_.Length/1KB) } 
 }, FullName, <some_other_property> | Out-File $OutputFile
 
我的问题是,从命令行运行此脚本会得到所需的结果

但是,在Azure管道构建过程中运行此操作会带来两件坏事:

当行较长时,剪切FullName列中的行: 不显示其他属性,例如 如果我将FullName转换为Name,一切正常,但我确实需要FullName属性

因为我在一个空气间隙的环境中工作,我不能复制所有的输出和所有的东西


我尝试对Out文件使用-Width标志,但没有成功。

我相信在引擎盖下发生的事情,ps使用创建的对象的ToString方法,该方法将其输出为Format Table cmdlet。由于窗口的大小,您会得到截断的属性。要查看它,您可以使用:

(Get-Host).ui.RawUI.WindowSize
可能这个太小了

我的建议如下:

将对象导入格式表 要解决此问题,可以使用-Property参数,该参数必须为:

$propertWidth = [int]((Get-Host).ui.RawUI.WindowSize.Width / 3)
$property = @(
    @{ Expression = 'LastWriteTime'; Width = $propertWidth; },
    @{ Expression = 'Size(KB)'; Width = $propertWidth; },
    @{ Expression = 'FullName'; Width = $propertWidth; }
)

... | Format-Table -Property $property -Wrap | ...
如果您不介意在文件中添加JSON,您可以使用: 但要考虑ConvertToJSON的默认深度为2。如果有嵌套对象,这也会截断对象。但就房产长度而言,它也可以

Get-ChildItem $Path -File -Recurse | Select-Object -Property LastWriteTime, @
 {
  label = "Size(KB)"
  expr = {  [string]::Format("{0:0.00}", $_.Length/1KB) } 
 }, FullName, <some_other_property> | Format-Table | Out-String | Out-File $OutputFile
LastWriteTime     Size(KB)       Name
------------      -------        ----
<some_date>       <some size>   ASomeWhatLong
                                foobarfoobarfo
                                foobarfoobarfo
$propertWidth = [int]((Get-Host).ui.RawUI.WindowSize.Width / 3)
$property = @(
    @{ Expression = 'LastWriteTime'; Width = $propertWidth; },
    @{ Expression = 'Size(KB)'; Width = $propertWidth; },
    @{ Expression = 'FullName'; Width = $propertWidth; }
)

... | Format-Table -Property $property -Wrap | ...
Get-ChildItem $Path -File -Recurse | Select-Object -Property LastWriteTime, @
 {
  label = "Size(KB)"
  expr = {  [string]::Format("{0:0.00}", $_.Length/1KB) } 
 }, FullName, <some_other_property> | ConvertTo-Json | Out-File $OutputFile