Я предлагаю это:
#Loop from row 1 to 13
for ($row = 1; $row -le 13; $row++) {
$destinationOU = $WorkSheet.Cells.Item($row, 1).Text
#Read all the cells to right of column 2 (until an empty cell is found)
$col = 2
while (($WorkSheet.Cells.Item($row, $col).Text) -ne "") {
$GPO = $WorkSheet.Cells.Item($row, $col).Text
set-GPLink -Name $GPO -Target $destinationOU -LinkEnabled yes
$col++
}
}
Может быть безопаснее пройти через используемый диапазон:
for ($row = 1; $row -le $WorkSheet.UsedRange.Row.Count; $row++) {
$destinationOU = $WorkSheet.Cells.Item($row, 1).Text
for ($col = 2; $col -le $WorkSheet.UsedRange.Columns.Count; $col++) {
$GPO = $WorkSheet.Cells.Item($row, $col).Text
set-GPLink -Name $GPO -Target $destinationOU -LinkEnabled yes
}
}