PowerShell Script Execution

I have created a script with atert.ps1 extention, Script is to send email atert when server reduntancy is lost. but i am unable to execute the script.

EmailFrom="aacrexch07@domain.com"
EmailTo="username1@domain.com"
RemoteSMTPServer="aacrexch07"
RemoteSMTPPort="25"
RemoteSMTPUser="username2@domain.com"
RemoteSMTPPass="testpassword"
Mailsubject = "Dell Server Alert on AACREXCH07"

Dim AlertConfig(38)
AlertConfig(0)="redunlost|Redundancy lost"


Run in powershell as Dellalert.ps1 testemail

but getting an error  The term 'EmailFrom=aacrexch07@domain.com' is not recognized as the name of a cmd
let, function, script file, or operable program. Check the spelling of the name
, or if a path was included, verify that the path is correct and try again.
At C:\script\DellAlert.ps1:1 char:32
+ EmailFrom="aacrexch07@domain.com" <<<<
    + CategoryInfo          : ObjectNotFound: (EmailFrom=aacrexch07@domain.com:S
   tring) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
sumod_jacobSenior IT ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wls3Commented:
Your syntax looks like VBScript.  Variables need to be preceded with dollar signs (such as $EmailFrom) and Dim is a convention irrelevant to Powershell as a whole.
0
the_endjinnCommented:
Hi, this looks very much like a VBscript. I would suggest renaming the file to alert.vbs and then calling it from the command line thus:

cscript.exe alert.vbs

If you are interested in PowerShell then I would suggest you start here: http://technet.microsoft.com/en-us/scriptcenter/dd742419
0
sumod_jacobSenior IT ManagerAuthor Commented:

I have modified as below, but getting C:\Script\script2.vbs(1, 1) Microsoft VBScript compilation error: Invalid character

$EmailFrom = "aacrexch07@domain.com"
$EmailTo = "username1@domain.com"
$SMTPServer = "aacrexch07.domain.com"
$SMTPPort = "25"
$SMTPUser = "alert@domain.com"
$SMTPPassword = "password"
$MailSubject = "Dell Server Alert on AACREXCH07"

Dim AlertConfig (38)
AlertConfig(0) = "redunlost|Redundancy lost"
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

the_endjinnCommented:
Sorry, looks like you have followed both bits of advice. You either need to leave the script without the $ and call from cscript or put the $ in front of the variables and remove the dim then call it a ps1 and run in power shell.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sumod_jacobSenior IT ManagerAuthor Commented:

Run as cscript script3.vbs testemail (Run Successfully, but not email received)

EmailFrom="aacrexch07@domain.com"
EmailTo="username1@domain.com"
SMTPServer="aacrexch07"
SMTPPort="25"
SMTPUser="alert@domain.com"
SMTPPassword="aacr123"
MailSubject="Dell Server Alert on AACREXCH07"


Dim AlertConfig (38)
AlertConfig(0) = "redunlost|Redundancy lost"





0
wls3Commented:
I do not see anything actually calling a function (or sub) to send the email.  This link has helped me accomplish this plenty of times:

http://www.paulsadowski.com/wsh/cdo.htm
0
sumod_jacobSenior IT ManagerAuthor Commented:
This will not help me... appreciate if your could do to write one sample script for me...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.