二维数组中的输出错误

时间:2019-02-08 08:12:54

标签: powershell

$ArrReiniger = Invoke-Sqlcmd -ServerInstance $instance -QueryTimeout 600     -Database $DB -Username $User -Password $Pass -Query $QueryReiniger|
               Select-Object -Property Reiniger
$Reiniger2 = $ArrReiniger -replace "@{Reiniger=",""
$Reiniger = $Reiniger2 -replace "}",""

foreach ($Team in $Reiniger) {
    $QueryGebiet = "SELECT TEXT13 as Gebiet FROM dbo.ADDRESSES WHERE TEXT13 IS NOT NULL AND TEXT47 = '" + $Team + "' GROUP BY TEXT13"
    $ArrGebiet = Invoke-Sqlcmd -ServerInstance $instance -QueryTimeout 600 -Database $DB -Username $User -Password $Pass -Query $QueryGebiet |
                 Select-Object -Property Gebiet

    foreach ($Region in $ArrGebiet) {
        $Team
        $Region
        "\$Team\$Region\Export $((Get-Date).ToString('dd-MM-yyyy')).csv"
    }
}

替换:

$Region2 = $ArrGebiet -replace "@{Gebiet=",""
$Region = $Region2 -replace "}",""

当我执行此脚本时,$Region的输出正确为“ 3”。 但是字符串中相同的变量$Region的输出为“ @ {Gebiet = 3}”。

我也尝试过替换不必要的字符,就像我之前用“ Reiniger”所做的那样,但是因为输出是数组中的所有值,所以它无济于事。

例如:

现在我的代码:

\First Place\@{Gebiet=1}\Export 08-02-2019.csv
\First Place\@{Gebiet=2}\Export 08-02-2019.csv
\First Place\@{Gebiet=3}\Export 08-02-2019.csv

替换:

\First Place\1 2 3\Export 08-02-2019.csv
\First Place\1 2 3\Export 08-02-2019.csv
\First Place\1 2 3\Export 08-02-2019.csv

应该如何:

\First Place\1\Export 08-02-2019.csv
\First Place\2\Export 08-02-2019.csv
\First Place\3\Export 08-02-2019.csv

0 个答案:

没有答案