Question: I'm building a PowerShell script to export a list of all the site collections in a particular web application.

So far I have this:

```
Get-SpWebApplication http://www.contoso.com | Get-SPSite -Limit All |
Select URL, ID, contentdatabase, owneralias,
secondaryowneralias | Export-CSV "f:\VLESites.csv" -NoTypeInformation

```

This creates a csv file at the specified drive location containing a list of site collection URLs, GUIDs and Content DBs within the stated web app. 
So far so good. 

Unfortunately it doesn't display the primary and secondary owners of the site collections.

How can I modify this script to also display this ower information?

Answer: 
Try to use [Owner](https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.spsite.owner.aspx) instead of `owneralias`, and [SecondaryContact](https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.spsite.secondarycontact.aspx) instead of `secondaryowneralias`.
Here is the script. It will get you primary administrators in an excel file for each site collection inside a web application. I am not able to get Secondary Owner Property though.

```
$WebApplicationUrl = "https://peopletest.brookfield.com"
$outputFile1 = "C:\TEMP\siteCollectionAdminsPrimary.csv"
$outputFile2 = "C:\TEMP\siteCollectionAdminsSecondary.csv"
$primarySiteAdminsCollection = @() #variable that will contain all the primary Site Collection Admins and will be exported
$secondarySiteAdminsCollection = @() #variable that will contain all the secondary Site Collection Admins and will be exported

$webApplication = Get-SPWebApplication $WebApplicationUrl;
if($webApplication -ne $null)
{
    ##Looping through all the site collections in the provided web application
    foreach($siteCollection in $webApplication.Sites)
    {
        $primarySiteAdminsCollection += $siteCollection.Owner
         $secondarySiteAdminsCollection += $siteCollection.SecondaryContact
    }
    $primarySiteAdminsCollection | ConvertTo-Csv -Delimiter "~" -NoTypeInformation | Out-File -Append -FilePath $outputFile1
    $secondarySiteAdminsCollection | ConvertTo-Csv -Delimiter "~" -NoTypeInformation | Out-File -Append -FilePath $outputFile2
}

```