I have created a Powershell script which fetch security group Members of specific account from multiple remote servers. But, the output I am getting is annoying. Assume group member as Server_Admins, Server_Admins1 and so on, then I want output as below:
But, I am getting output in below format:
Members Group Name
user1 user2 user3 user4 Server_Admin
user5 user6 user7 user8 Server_Admin1
$secgroups = Get-Content C:\Users\user1\Desktop\test.txt
$array = @()
PowerShell's formatting system will produce a table when you give it less than 5 properties, by default. If you want something other than that, you're going to need to code it out yourself. You'll have to enumerate each one and output whatever you want.
Output formatting is frankly not PowerShell's strongest superpower – if you want anything more than the default, you end up having to code it up yourself.
What about just doing something like the following...
### Show User and AD group membership
# Get users with all their properties and their group membership, display user and group name
# Get users with base properties and their group membership, display user and group name
# Get user and AD group info, display user and group name
Get-ADUser -Filter "*" -SearchBase "CN=users,DC=contoso,DC=com" -SearchScope OneLevel -Properties Name, MemberOf |
Of course format as needed.
You must be logged in to reply to this topic.