Geliosvamp
11-08-2014, 14:30
В $b помещается массив, например, @("CN=Иванов Иван Иваныч,OU=Users,DC=corp,DC=ulsk,DC=loc", "CN=Семенов Семен Семеныч,OU=Users,DC=corp,DC=ulsk,DC=loc").
Далее необходимо выудить у данных учётных записей значения полей name, title и department. Я решил всё это засунуть в одноименные массивы $name, $title и $department.
$name = @()
$title = @()
$department = @()
$b = @(Get-ADGroupMember $n | ForEach {$_.distinguishedName})
$nn = $b.Count - 1
for ($i=0;$i -le $nn ;$i++)
{
Get-ADUser -Identity $b[$i] -Properties * | ForEach-Object {$name[$i] = $_.name; $title[$i] = $_.title; $department[$i] = $_.department}
}
Выскакивает ошибка:
Index was outside the bounds of the array.
E:\PS.ps1:93 знак:81
+ ... orEach-Object {$name[$i] = $_.name; $title[$i] = $_.title; $department[$i] = $_. ...
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException
+ FullyQualifiedErrorId : System.IndexOutOfRangeException
Index was outside the bounds of the array.
E:\Docs\PS.ps1:93 знак:102
+ ... $i] = $_.name; $title[$i] = $_.title; $department[$i] = $_.department}
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException
+ FullyQualifiedErrorId : System.IndexOutOfRangeException
Index was outside the bounds of the array.
E:\Docs\PS.ps1:93 знак:125
+ ... i] = $_.title; $department[$i] = $_.department}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException
+ FullyQualifiedErrorId : System.IndexOutOfRangeException
Собственно 93 знак:81 - это $name[$i] = $_.name.
$name[$i] = @($_.name) - тоже не спасает.
Что я не так делаю?
Далее необходимо выудить у данных учётных записей значения полей name, title и department. Я решил всё это засунуть в одноименные массивы $name, $title и $department.
$name = @()
$title = @()
$department = @()
$b = @(Get-ADGroupMember $n | ForEach {$_.distinguishedName})
$nn = $b.Count - 1
for ($i=0;$i -le $nn ;$i++)
{
Get-ADUser -Identity $b[$i] -Properties * | ForEach-Object {$name[$i] = $_.name; $title[$i] = $_.title; $department[$i] = $_.department}
}
Выскакивает ошибка:
Index was outside the bounds of the array.
E:\PS.ps1:93 знак:81
+ ... orEach-Object {$name[$i] = $_.name; $title[$i] = $_.title; $department[$i] = $_. ...
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException
+ FullyQualifiedErrorId : System.IndexOutOfRangeException
Index was outside the bounds of the array.
E:\Docs\PS.ps1:93 знак:102
+ ... $i] = $_.name; $title[$i] = $_.title; $department[$i] = $_.department}
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException
+ FullyQualifiedErrorId : System.IndexOutOfRangeException
Index was outside the bounds of the array.
E:\Docs\PS.ps1:93 знак:125
+ ... i] = $_.title; $department[$i] = $_.department}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException
+ FullyQualifiedErrorId : System.IndexOutOfRangeException
Собственно 93 знак:81 - это $name[$i] = $_.name.
$name[$i] = @($_.name) - тоже не спасает.
Что я не так делаю?