각 그룹의 구성원과 함께 Active Directory의 그룹 목록을 함께 컴파일하는 PowerShell 스크립트를 작성하려고합니다. 나의 궁극적 인 목표는 CSV 파일이 밖으로 내보내는 것입니다, 그래서 최종 PowerShell을 다차원 배열은 다음과 같은 형식으로 갖고 싶어 : 나는 시도하고이 작업을 수행하려면 다음 코드를 사용하고PowerShell 배열/추가 구성원에 데이터 추가
GroupName GroupMember
Domain Admins Henry Doe
Domain Admins Melody Doe
Domain Names Doe Ray Me
Domain Users John Doe
Domain Users Jane Doe
(etc…)
:
를[array]$arrGroupMemberList = New-Object PSObject
Add-Member -InputObject $arrGroupMemberList -membertype NoteProperty -Name 'GroupName' -Value ""
Add-Member -InputObject $arrGroupMemberList -membertype NoteProperty -Name 'GroupMember' -Value ""
[array]$arrGroupMemberList = @()
[array]$arrGroupNameObjects = Get-ADGroup -Filter * | Where-Object {$_.Name -Like "Domain*"}
If ($arrGroupNameObjects.Count -ge 1)
{
## Cycle thru each group name and get the members
$arrGroupNameObjects | ForEach-Object {
[string]$strTempGroupName = $_.Name
$arrGroupMemberObjects = Get-ADGroupMember $strTempGroupName -Recursive
If ($arrGroupMemberObjects.Count -ge 1)
{
## Cycle thru the group members and compile into the final array
$arrGroupMemberObjects | ForEach-Object {
$arrGroupMemberList += $strTempGroupName, $_.Name
}
}
}
}
내 문제는, 내가 내 배열로 다음과 같이 끝나는 계속 :
Domain Admins
Henry Doe
Domain Admins
Melody Doe
Domain Names
Doe Ray Me
Domain Users
John Doe
Domain Users
Jane Doe
나는 몇 가지 방법을 시도하고 내가 검색 한하지만 어디 답을 발견하지 않았습니다. 나는 그것이 단순한 것이라고 확신하지만 잘못된 것은 무엇인가? 해야 할 일과 같이 필요한 데이터로 다차원 배열을 만들 수 있습니까? 내가 사용하는 경우 대신 다음
## Cycle thru the group members and compile into the final array
$arrGroupMemberObjects | ForEach-Object {
$arrGroupMemberList[$intIndex].GroupName = $strTempGroupName
$arrGroupMemberList[$intIndex].GroupMember = $_.Name
$intIndex++
내가 좋아하는 오류와 끝까지 :
Property 'GroupMember' cannot be found on this object; make sure it exists and is settable.
Property 'GroupName' cannot be found on this object; make sure it exists and is settable.
감사
는 ** UPDATE **
나는 밖으로 어디에서 발견 할 수 있습니다 내 문제는 배열 구성원을 추가 할 때 수 있습니다. 내 PowerShell 스크립트의 끝에서, 나는 다음 코드 줄 추가하고 :
$arrGroupMemberList | Get-Member
더 속성이 없습니다를 내 요소는 앞서 스크립트에 추가-Member cmdlet으로 그들을 추가에도 불구하고,이 없습니다. Add-Member cmdlet을 제대로 사용하고 있습니까?
감사하지만 시도했지만 여전히 작동하지 않았습니다. 나를 위해. 새로운 정보를 발견하고 내 질문을 업데이트 할 것입니다. – STGdb