Avatar of Andy Andy
Andy Andy
Flag for India

asked on 

join three command to one script

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 "http://exchangecasarray.contoso.com/powershell" -Credential $Credential -Authentication Kerberos -AllowRedirection
Import-PSSession $session
Set-AdServerSettings -ViewEntireForest $true


second smtp setting

$smtpsettings = @{
    To =  "administrator@exchangeserverpro.net"
    From = "exchangeserver@exchangeserverpro.net"
    Subject = "$reportemailsubject - $now"
    SmtpServer = "smtp.exchangeserverpro.net"


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.

Avatar of undefined
Last Comment
Andy Andy

8/22/2022 - Mon