Returning MemberOf as a string from an AD query


i'm using quest add-on query ad , want csv list of users few properties , groups in. like:

user1, group1, user1property, user1property, etc...
user1, group2, user1property, user1property, etc...
user2, group1, user2property, user2property, etc...
user2, group2, user2property, user2property, etc...

pretty straightforward think. load users , groups memory , interleave them. instead of getting group name, i'm getting looks single value hash table: @{name=groupname}. how text of group name?

line breaks readability:

write "" write "running...."  write "username, group, lastname, firstname, creationdate, modificationdate, accountisdisabled,
accountislockedout, accountexpires, lastlogon, passwordlastset, passwordexpires, passwordneverexpires" # write "username, group, lastname, firstname, creationdate, modificationdate, accountisdisabled,
accountislockedout, accountexpires, lastlogon, passwordlastset, passwordexpires, passwordneverexpires" | out-file accessquery.csv $allusers = get-qaduser -sizelimit 0 $allgroups = get-qadgroup -sizelimit 0 foreach ($user in $allusers) { foreach ($groupdn in $($user.memberof)) { $groupname = $allgroups | {$_.dn -like "$groupdn"} | select name write "$($user.samaccountname), $groupname, $($user.lastname), $($user.firstname),
$($user.creationdate), $($user.modificationdate), $($user.accountisdisabled), $($user.accountislockedout), $($user.accountexpires), $($user.lastlogon), $($user.passwordlastset), $($user.passwordexpires), $($user.passwordneverexpires)" # write "$($user.samaccountname), $groupname, $($user.lastname), $($user.firstname), $($user.creationdate), $($user.modificationdate), $($user.accountisdisabled), $($user.accountislockedout), $($user.accountexpires), $($user.lastlogon), $($user.passwordlastset), $($user.passwordexpires), $($user.passwordneverexpires)" | out-file accessquery.csv -append } } write "" write "query complete! see accessquery.csv."

actually $($group.name) worked charm. should have tried before. :)

guys.


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Azure MFA with Azure AD and RDS

Failed to setup initiator portal. Error status is given in the dump data.

Invalid pointer on gpresult /h gpreport.html