I had a really long script for a while but I've got a bit better and pipe things shorter (should be a trademark), so here is my new attempt on this topic:
Instead of 68 lines I now get things done in
- $list = @()
- Get-ADUser -Filter "Name -like ""*""" -SearchBase "OU=Users,DC=contoso,DC=eu" -Properties name | % {
- $name = $_.name
- $_ | Get-ADPrincipalGroupMembership | % {
- $line = New-Object PSObject
- $line | Add-Member -MemberType NoteProperty -Name "Name" -Value $name
- $line | Add-Member -MemberType NoteProperty -Name "Group" -Value $($_.name)
- $line | Add-Member -MemberType NoteProperty -Name "Manager" -Value $($_ | Get-ADGroup -Properties managedBy | Select -ExpandProperty managedBy | Get-ADObject | Select -ExpandProperty Name)
- $list = $list + $line
- }
- }
- $list | export-csv "c:\temp\usergroups.csv" -Encoding Unicode
If anyone has good hints on creating PSObjects with many properties in one line, let me know in comments ;)
No comments:
Post a Comment