Andy Andy
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.Automati on.PSCrede ntial -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@exchangeser verpro.net "
From = "exchangeserver@exchangese rverpro.ne t"
Subject = "$reportemailsubject - $now"
SmtpServer = "smtp.exchangeserverpro.ne t"
}
========================== ========== ========== ====
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.
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.Automati
$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@exchangeser
From = "exchangeserver@exchangese
Subject = "$reportemailsubject - $now"
SmtpServer = "smtp.exchangeserverpro.ne
}
==========================
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.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Awsum.. i tried
it runs perfectly fine.. thank you so much
but outlook comes like below in email, can this be adjusted correctly, as seen Name and component are together
Name Component State
---- --------- -----
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup Active
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup Active
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup Active
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup Active
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup Active
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup Active
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup Active
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup Active
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
it runs perfectly fine.. thank you so much
but outlook comes like below in email, can this be adjusted correctly, as seen Name and component are together
Name Component State
---- --------- -----
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
ServerWideOffline Active
HubTransport Active
FrontendTransport Active
Monitoring Active
RecoveryActionsEnabled Active
AutoDiscoverProxy Active
ActiveSyncProxy Active
EcpProxy Active
EwsProxy Active
ImapProxy Active
OabProxy Active
OwaProxy Active
PopProxy Active
PushNotificationsProxy Active
RpsProxy Active
RwsProxy Active
RpcProxy Active
UMCallRouter Active
XropProxy Active
HttpProxyAvailabilityGroup
ForwardSyncDaemon Active
ProvisioningRps Active
MapiProxy Active
EdgeTransport Active
HighAvailability Active
SharedCache Active
"Name and component are together" - not correct, the name is empty. You probably have a different Exchange release than I. But for better formatting, try the HTML mail version, and replace "Name" with "Identity":
# Send as plain text mail
# Send-MailMessage @smtpsettings -Body (Get-ExchangeServer | Get-ServerComponentState | ft -a Identity, Component, State | Out-String)
# or send as HTML mail.
Send-MailMessage @smtpsettings -BodyAsHTML -Body (Get-ExchangeServer | Get-ServerComponentState | select Identity, Component, State | convertTo-HTML)
ASKER
i think you are not getting my query, i mean output that coming in email
is not in format
the data going here and dere like below
means if column status the below data not come below to status, it is not in format.
i mean exact like below it need to be
State
Active
Active
Active
is not in format
the data going here and dere like below
means if column status the below data not come below to status, it is not in format.
i mean exact like below it need to be
State
Active
Active
Active
ASKER
Thank you so much
i am so Thankful to EE to have so brilliant engineers, its worth to have a Subscription on EE
i am so Thankful to EE to have so brilliant engineers, its worth to have a Subscription on EE
With the latest change you get your email in HTML format. Maybe your mail client does not accept/display HTML mail - if this is the case, there is nothing we can do. For plain text to be properly formatted you need to have a mono-spaced (non-proportional) font in your email client.
ASKER
Got it.. Many thanksss
ASKER
Got it.. Many thanksss
ASKER
and also i need to jst change username and password syntax above
You are Really a Champ !!
Thanks,
Andy