0

I have construct powershell to get sitecollection information. What i am trying to achieve is to get all email address of site owner email address and secondary owner email address and put in the CC field in new email. The function required to check if any duplicate email before add to CC field in new email draft.

here is the following code that i have so far. Thank you

if (( Get-PSSnapin -Name “Microsoft.SharePoint.Powershell” -ErrorAction SilentlyContinue) -eq $null) 
{ 
    Add-PSSnapin Microsoft.SharePoint.Powershell 
} 
Import-Module ActiveDirectory -ErrorAction SilentlyContinue
$sites = Get-SPSite -Limit ALL

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
#Configure the location for the output file

$now = Get-Date
$timestamp = $now.toString("yyyyMMddhhss")
$Output=$timestamp + "_Output.csv";



"Site URL"+","+"Owner Email"+"Secondary Email"+","+"Total Storage Used (MB)"+","+"Site Quota Percentage Used" | Out-File -Encoding Default -FilePath $Output;
#Specify the root site collection within the Web app




#Loops through each site collection within the Web app, if the owner has an e-mail address this is written to the output file
Foreach ($Site in $sites)
{if ($Site.Quota.Storagemaximumlevel -gt 0) {[int]$MaxStorage=$Site.Quota.StorageMaximumLevel /1MB} else {$MaxStorage="0"}; 
if ($Site.Usage.Storage -gt 0) {[int]$StorageUsed=$Site.Usage.Storage /1MB};
if ($Storageused-gt 0 -and $Maxstorage-gt 0){[int]$SiteQuotaUsed=$Storageused/$Maxstorage* 100} else {$SiteQuotaUsed="0"}; 
$Web=$Site.Rootweb; 


$Site.Url + "," + $Site.Owner.Name + "," +$Site.SecondaryContact.Email +","+$StorageUsed + "," + $SiteQuotaUsed | Out-File -Encoding Default -Append -FilePath $Output;$Site.Dispose()};
1

Assuming I understand your question, you want to email the csv file and cc the site owners and secondary contacts the file as well. This should do what you were looking for assuming the rest of your code was correct. Please keep in mind you will have to change the appropriate values.

if (( Get-PSSnapin -Name “Microsoft.SharePoint.Powershell” -ErrorAction SilentlyContinue) -eq $null) 
    { 
        Add-PSSnapin Microsoft.SharePoint.Powershell 
    } 
    Import-Module ActiveDirectory -ErrorAction SilentlyContinue
    $sites = Get-SPSite -Limit ALL

    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
    #Configure the location for the output file

    $now = Get-Date
    $timestamp = $now.toString("yyyyMMddhhss")
    $Output=$timestamp + "_Output.csv";

    $CCEmails =@()

    "Site URL"+","+"Owner Email"+"Secondary Email"+","+"Total Storage Used (MB)"+","+"Site Quota Percentage Used" | Out-File -Encoding Default -FilePath $Output;
    #Specify the root site collection within the Web app




    #Loops through each site collection within the Web app, if the owner has an e-mail address this is written to the output file
    Foreach ($Site in $sites)
    {if ($Site.Quota.Storagemaximumlevel -gt 0) {[int]$MaxStorage=$Site.Quota.StorageMaximumLevel /1MB} else {$MaxStorage="0"}; 
    if ($Site.Usage.Storage -gt 0) {[int]$StorageUsed=$Site.Usage.Storage /1MB};
    if ($Storageused-gt 0 -and $Maxstorage-gt 0){[int]$SiteQuotaUsed=$Storageused/$Maxstorage* 100} else {$SiteQuotaUsed="0"}; 
    $Web=$Site.Rootweb; 


    $Site.Url + "," + $Site.Owner.Name + "," +$Site.SecondaryContact.Email +","+$StorageUsed + "," + $SiteQuotaUsed | Out-File -Encoding Default -Append -FilePath $Output;

    #Add Site Owner Email To Array
    if ($CCEmails -notcontains $Site.Owner.Email)
    {
        $CCEmails += $Site.Owner.Email
    }
    #Add Secondary Site Owner Email To Array
        if ($CCEmails -notcontains $Site.SecondaryContact.Email)
    {
        $CCEmails += $Site.SecondaryContact.Email
    }

    $Site.Dispose() 
    };

$SMTP = 'Your smtp'
send-mailmessage -from "From Email Address" -to "To Email Address" -Cc $CCEmails -subject "Subject" -Attachments @($Output) -BodyAsHTML -body ([System.String] "Body of email") -priority "Low" -smtpServer $SMTP

Reference on Send mail message:

http://technet.microsoft.com/en-us/library/hh849925.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.