简体   繁体   中英

How to use Group-Object to extract key info and ConvertTo-HTML

I have a csv file with various email addresses and collaborators. I then use | Group-Object INVITER_EMAIL -AsHashTable –AsString | Group-Object INVITER_EMAIL -AsHashTable –AsString to create a hash table with keys where an INVITER_EMAIL can have multiple collaborators.

I am able to show on screen using:

foreach ($User in $Collaborators.keys) {
  $Collaborators[$User] | select INVITER_EMAIL,COLLABORATOR_LOGIN,INVITE_ACCEPTED,ITEM_NAME,URL_TO_ITEM       
}

but when I try to pipe | ConvertTo-HTML | ConvertTo-HTML it won't format the string correctly.
I can do [string]$Collaborators.'user@email.com' which gives me the correct HTML I want to generate for one user, but having difficulty getting this to go through the foreach loop. Not sure what I may be missing, but I'm hoping to get each of these into a separate $body of a form email at some point. Not sure if this is possible or not? Thx

$Collaborators

Name                           Value                                                                                                                                                                                      
----                           -----                                                                                                                                                                                      
user@email.com           {@{REAL_OWNER_EMAIL_DOMAIN=somewhere; REAL_OWNER_EMAIL=user@email.com; REAL_OWNER_FIRST_NAME=Anna; REAL_OWNER_LAST_NAME=Someone; OWNER_LOGIN=admins@email...

I think you are started correctly in your question.

But the idea is getting information of each person and combining from it a new object and putting it to the array. You just need to create a customObject in each loop cycle.

For Example.

foreach ($User in $Collaborators.keys) {
    [array]$MyList += [PSCustomObject]@{
        Email = $Collaborators[$User].Name
        Inviter = $Collaborators[$User].INVITER_EMAIL
        Login = $Collaborators[$User].COLLABORATOR_LOGIN
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM