【发布时间】:2016-07-31 03:12:12
【问题描述】:
我正在尝试在此脚本中使用$a 变量来处理中间步骤,这样我就不必重复使用$array[$array.Count-1]。 $prop 也是如此。但是,值正在被循环中的最后一个值覆盖。
$guests = Import-Csv -Path C:\Users\shant_000\Desktop\UploadGuest_test.csv
$output = gc '.\Sample Json.json' | ConvertFrom-Json
$array = New-Object System.Collections.ArrayList;
foreach ($g in $guests) {
$array.Add($output);
$a = $array[$array.Count-1];
$a.Username = $g.'EmailAddress';
$a.DisplayName = $g.'FirstName' + ' ' + $g.'LastName';
$a.Password = $g.'LastName' + '123';
$a.Email = $g.'EmailAddress';
foreach ($i in $a.ProfileProperties.Count) {
$j = $i - 1;
$prop = $a.ProfileProperties[$j];
if ($prop.PropertyName -eq "FirstName") {
$prop.PropertyValue = $g.'FirstName';
} elseif ($prop.PropertyName -eq "LastName") {
$prop.PropertyValue = $g.'LastName';
}
$a.ProfileProperties[$j] = $prop;
}
$array[$array.Count-1] = $a;
}
$array;
【问题讨论】:
-
$output = gc '.\Sample Json.json' | ConvertFrom-Json->$outputJson = gc '.\Sample Json.json',$array.Add($output)->[void]$array.Add(($outputJson | ConvertFrom-Json))
标签: arrays powershell