Saddly - not good this time guys.
Ive created a new folder. and two files within the folder : Main.ps1 and func-emal.ps1.
I then call main.ps1 from the PS shell with it set in the folder containing the file.
#Main
<pre>
. ./func-email.ps1
</pre>
write-host "Loaded Main"
$oReturned = sendemail "pstest@wibble.co.uk" "tgent@wibble.co.uk" "SubjectLine" "Text Line"
write-host $oReturned.
#Func-email contains just :
function sendemail {
param ($sFrom, $sTo, $sSubj, $sTxt)
$sEmailSvr = "alfred.server"
$SmtpClient = New-Object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$SmtpClient.host = $sEmailSvr
$MailMessage.from = $sFrom
$MailMessage.To.add($sTo)
$MailMessage.IsBodyHtml = 1
$MailMessage.Subject = $sSubj
$MailMessage.body = $sTxt
#$MailMessage.Attachments.Add("c:\temp\report.txt")
$oResult = $SmtpClient.Send($MailMessage)
write-host $oResult
return $oResult
}
When I run the Main from the power shell - it fails with the following error :
The term '<'<' is not recognized as a cmdlet, function, operable program, or scri
pt file. Verify the term and try again.
At C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts\FuncInc\m
ain.ps1:4 char:2
If I replace Main1 with the following code :
#Main
Get-ChildItem scripts:\func-*.ps1 | % { . $_
write-host "Loading library file:`t$($_.name)"
}
write-host "Loaded Main"
$oReturned = sendemail "pstest@wibble.co.uk" "tgent@wibble.co.uk" "SubjectLine" "Text Line"
write-host $oReturned.
I get the following error :
Get-ChildItem : Cannot find drive. A drive with name 'scripts' does not exist.
At C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts\FuncInc\m
ain.ps1:3 char:14
+ Get-ChildItem <<<< scripts:\func-*.ps1 | % { . $_
Loaded Main
The term 'sendemail' is not recognized as a cmdlet, function, operable program,
or script file. Verify the term and try again.
At C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts\FuncInc\m
ain.ps1:8 char:23
+ $oReturned = sendemail <<<< "pstest@snsltd.co.uk" "tgent@snsltd.co.uk" "Subj
ectLine" "Text Line"
In short - neither attempt works. Am I missing something important. Please bare in mind - I'm a newb!
Many thanks for your assistance.
TG