Translate

Friday, June 14, 2013

Send-MailMessage : Unable to connect to remote server Line 1 character 17 error in PowerShell 2.0



After running below code 

Send-MailMessage -to "someone@somedomain.com" -from "DhimantR@somedomain.com" -Subject " Test message" -Body " Test message" -SmtpServer " 10.10.10.10"


If you run into error given below

Send-MailMessage : Unable to connect to the remote server 
At line:1 char:17
+ Send-MailMessage <<<< -to someone@somedomain.com -from "DhimantR@someDomain.com" -subject " Troubleshooting"  -Body   "Some Text or file attachement" -sntpserver "smtpserver" 
       + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException 
       + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.Send MailMessage

Try this solution

Solution: one of the possible problem is your anti-virus software blocking to connect SMTP server using PowerShell

In my case it is McAfee

Steps:

Right click on McAfee icon 
Click on Virus Scan Console
Double click on Access Protection on VirusScan Console
On Access Protection tab
Go to Anti-Virus Standard Protection
On right hand side, double click on Prevent mass mailing worms from sending mail
On process to exclude tab, add PowerShell.exe at the end
Click ok 
Click apply on Access Protection
Click ok


That's it and try again to send mail using Send-MailMessage 


Post  your question or comment

Wednesday, June 12, 2013

SCOM 2012 SP1 Power shell script for Maintenance Mode for group of servers at once and using Batch file

This blog will help putting group of computers in maintenance mode with just two double click in SCOM 2012 SP1


Three files needed

1)Server names in txt file
2) Powershell script
3) Batch file for execution

Prerequisites: This script needs to run in Management Server with admin or SCOM admin privileges

1

First create a txt file with your server names or group of servers

server1.domain.com
server2.domain.com
server3.domain.com
server4.domain.com

2

Now create a script named it script.ps1 

script content will be as below

_________________________________________________________________________________
Import-module -name OperationsManager;
new-SCOMManagementGroupConnection -ComputerName Localhost;
$Class = get-SCOMclass | where-object {$_.Name -eq "Microsoft.Windows.Computer"};
$time = [DateTime]::Now;
$service = get-content d:\psscript\Servers_1AM.txt | where{$_}
foreach ($i in $service)
{
echo "$i";
$Instance = get-SCOMClassInstance -class $Class | Where-Object {$_.Displayname -eq "$i"};
Start-SCOMMaintenanceMode -instance $Instance -endtime $time.addMinutes(15) -reason "Plannedother" -comment "Test of MM for AppPool";
echo "Starting maintenance mode";
}
_______________________________________________________________________________

This script will than be passed to power shell in batch file for execution



3

Now create a batch file servergroup1.bat, this file will help you with a double click your entire group will be put under maintenance mode


________________________________________________________________________________

powershell.exe -noexit d:\locationof script\script1.ps1                                                                                  _________________________________________________________________________________

Post your question or comment