I created a custom object in PowerShell. I was able to solve the problem I wanted to solve. I wanted to have an object with two columns, one for the site collection, one for the email.
However, I am wondering if there is an easier solution. Do you have any suggestions?
Here is my code:
$cred = Get-Credential
Connect-PnPOnline "https://tenant.sharepoint.com" -Credentials $cred
$SiteCollections = Get-PnPTenantSite
$object = @()
foreach ($SiteCollection in $SiteCollections) {
Connect-PnPOnline -Url $SiteCollection.Url -Credentials $cred
$email = Get-PnPRequestAccessEmails
Write-Host "Email for $($SiteCollection.Url): $($email)"
$obj = New-Object System.Object
$obj | Add-Member -type NoteProperty -name Url -value $SiteCollection.Url
$obj | Add-Member -type NoteProperty -name Email -value $email
$object += $obj
}
Write-Output $object