Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Removing blank spaces and blank lines from output

$
0
0

Hi All,

I need a bit of a help with the script I have written . This script works on a SharePoint site, it pulls the list of the users from the group having string "owner" in their name and send them emails . The script is working fine but whenever email ids of the users are pulled from the group a blank line is appended to the output which results in an error . Below is the script  :

===============================================================

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$sitecoll = gc .\Site_list.txt
ForEach($url in $sitecoll)
{
$site = [Microsoft.SharePoint.SPSite] ($url)
$Web = $site.OpenWeb()
foreach($group in $Web.Groups)
{
if($group.Name -like "*Owner*")
{
foreach($user in $group.Users)

$emailTo=($user.email).trimend()
$emailTo
$template = "xxx " 
$signature = "xxx"
$carboncopy="<xyz@abc.com>"
$emailFrom = "<ayz@abc.com>"
$subject = "xxx :" + $site.url
$body = $template + $signature 
$smtpServer = "smtp.abc.com"
##send-MailMessage -SmtpServer $smtpserver -To $emailTo -BCC $carboncopy -From $emailFrom -Subject $subject -Body $body -BodyAsHtml
}
}
}
}

=============================================================

Below is the output that is passed to the send-MailMessage cmdlet :

aaa@abc.com

Blank Line

bbb@abc.com

Blank Line

ccc@abc.com

=================================================================

Can any one please help to remove these blank lines from the output .


Regards

Karan Sharma 



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>