troubleshooting Question

join three command to one script

Avatar of Andy Andy
Andy AndyFlag for India asked on
9 Comments1 Solution137 ViewsLast Modified:
I have below three syntax, that i need to put in single script.

my purpose is that, i want the the below exchange server components state will come to email, as i will put this .ps1 file in schedule task.

i am using remote powershell

$UserName = 'domain\username'
$Password = 'secret password'
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName, (ConvertTo-SecureString $Password -asPlaintext -Force)

$session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri "" -Credential $Credential -Authentication Kerberos -AllowRedirection
Import-PSSession $session
Set-AdServerSettings -ViewEntireForest $true


second smtp setting

$smtpsettings = @{
    To =  ""
    From = ""
    Subject = "$reportemailsubject - $now"
    SmtpServer = ""


output in email

Get-ExchangeServer | Get-ServerComponentState | ft

Please suggest, my purpose is to set this whole joined script in task scheudler and result will come on email.
"Batchelor", Developer and EE Topic Advisor

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2015

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros