Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.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
Powershell 如何在每个整数后添加新行_Powershell_Powershell 2.0_Powershell 3.0 - Fatal编程技术网

Powershell 如何在每个整数后添加新行

Powershell 如何在每个整数后添加新行,powershell,powershell-2.0,powershell-3.0,Powershell,Powershell 2.0,Powershell 3.0,我试图找出一种方法,使一个新变量从另一个变量输出到GUI。当我试图通过标签显示变量时,它会丢失换行符 在处理文本时,我设法找到了一个解决方案,但当涉及到数字时,它就不起作用了 以下是我尝试过的: $ActiveUnits = @(Get-MsolAccountSku | Select-Object -ExpandProperty ActiveUnits) $ActiveUnitsFix = "`n" foreach ($Unit in $ActiveUnits) { $ActiveU

我试图找出一种方法,使一个新变量从另一个变量输出到GUI。当我试图通过标签显示变量时,它会丢失换行符

在处理文本时,我设法找到了一个解决方案,但当涉及到数字时,它就不起作用了

以下是我尝试过的:

$ActiveUnits = @(Get-MsolAccountSku | Select-Object -ExpandProperty ActiveUnits)

$ActiveUnitsFix = "`n"

foreach ($Unit in $ActiveUnits) {
    $ActiveUnitsFix += @($Unit + "`n")
}
我得到的结果是:

31425220100002521100001000000100000002137328420 31425220100002521100001000000100000002137328420 当它应该是这样的时候:

3 14 25 220 10000 25 21 10000 1000000 10000000 213 7 3 28 4 20 3. 14 25 220 10000 25 21 10000 1000000 10000000 213 7. 3. 28 4. 20
如果从
(Get MsolAccountSku).ActiveUnits
接收到int数组,则可以使用
-join
参数添加新行

[System.Int32[]]$ActiveUnits  = (Get-MsolAccountSku).ActiveUnits
[System.String]$ActiveUnitsFix = $ActiveUnits -join [System.Environment]::NewLine
$ActiveUnitsFix

使用[environment]代替“`n”:NewLine@f6a4感谢您的回复,但是我尝试用[environment]替换“`n”::换行符和我仍然得到相同的结果
$ActiveUnits=Get MsolAccountSku | select ActiveUnits | format table-HideTableHeaders
对我来说,这非常有效
$ActiveUnits | Out String
如果你不使用
-ExpandProperty
,你会看到什么?这将为您提供一个数字数组或
[int]
。。。其中otta不显示为一行数字。。