PowerShell Send Email if Windows Service is in Stopped State
HTML-код
- Опубликовано: 20 авг 2024
- In This Video we are going to see how to send email if service is stopped with computer name. Here we are only checking if service state and sending email to respective email if it is stopped state. This script is add-on to video - • PowerShell Send email ... . Please check this video if you want to see how you can schedule PowerShell script in Task Scheduler.
======================= Script Here ======================
$ServiceName = Read-host 'Enter Service Name here'
$arrService = Get-Service -Name $ServiceName
$computerName = $env:COMPUTERNAME
$subject = "Service '$ServiceName' On The Computer '$computerName' is NOT Running"
$body = "Restart the service, if service is not starting then raise GSD ticket with priority 1 to Team SERVICENOW"
if ($arrService.Status -ne 'Running')
{
Send-MailMessage -From 'administrator@sitech.com' -To 'swapnil@sitech.com' -Subject $subject -body $body -SmtpServer 'mum-srv01.sitech.com'
(Get-Date).toString("yyyy/MM/dd HH:mm:ss") | Out-File -FilePath C:\Scripts\TestLog.txt -Append
Get-Service -Name $ServiceName | Out-File -FilePath C:\Scripts\TestLog.txt -Append
}
else
{
(Get-Date).toString("yyyy/MM/dd HH:mm:ss") | Out-File -FilePath C:\Scripts\TestLog.txt -Append
Get-Service -Name $ServiceName | Out-File -FilePath C:\Scripts\TestLog.txt -Append
}
======================================
PowerShell Send email if windows service is not running
• PowerShell Send email ...
Get Local Group Members from Remote computers
• Get Local Group Member...
PowerShell Script To Change Service Account or Update Password
• Powershell Script To C...
PowerShell How To Change Remote Computer (Workgroup) Local Account Password
• Powershell How To Chan...
Delete Virtual Machine Snapshots Older Than Specific Days
• Delete Multiple Virtua...
How To Create File Selection Dialog Box in PowerShell
• How To Create File Sel...
Add User/Group To The Local Administrators/RDP Group On Multiple Computers
• Add User/Group To The ...
Get Windows Updates list from Remote Computer
• Get Windows Updates li...
PowerShell Remotely Uninstall Software from Multiple Computers
• PowerShell Remotely Un...
PowerShell Search Specific KB Status on Remote Computers
• PowerShell Search Inst...
PowerShell Script to Connect Multiple Server's Remote Session
• PowerShell Script to C...
PowerCLI Script to power ON dedicated VMs listed in a text file
• PowerCLI Script to pow...
PowerCLI Script to power Off dedicated VMs listed in a text file
• PowerCLI Script to pow...
Delete Snapshot's from Multiple Virtual Machines
• Delete Snapshot's from...
Create Snapshot on Multiple Virtual Machine
• Create Snapshot on Mul...
How can I check if a port is open remotely
• Identify if Windows TC...
Installing software remotely on Multiple "Workgroup" Computers
• Installing software re...
PowerShell Installing software remotely on Multiple Computers
• PowerShell Installing ...
Unable to move OU in Active Directory (Access is denied)
• Unable to move OU in A...
PowerShell Installing software remotely on Multiple Computers
• PowerShell Installing ...
Get Multiple Services Status Remotely | Remotely Start or Stop Services
• Get Multiple Services ...
Get Date and Time from Multiple Remote Computers
• Get Date and Time from...
PowerCLI - How to get HA restarted VM's List
• PowerCLI - How to get ...
Get-Childitem - Search file on Local and Remote Computers
• Get-Childitem - Search...
Remotely Create Update Delete Registry Key on Multiple Computers
• Remotely Create Update...
Get service status from remote server's using PowerShell
• Get service status fro...
Thanks for your vedio it's very useful . We have one query you are using own mail server so password not required only entered mail server but other linke G-Suite mail id how to configure.
All your sessions are good and useful but in this video font size is very small and not able to see the script exactly 😢. Do you have any website where we can see it
Sorry for the font size, I have provided a script in the video description so you can copy it from there. Please let me know if you have any other queries.
If you had multiple services in the $ServiceName variable, how do you get it to send only the one service that's not running and not all the services?
If you add multiple services in services variable then you have to apply for each loop on that variable so during for each loop it will check services one by one and then you can mention if condition that if any service is in xyz condition then send email or do some action
Very informative sir. I have one question, please let me know how do i achieve it. I have a list of servers, which requires to be stopped and then restart, again. Generally we do this manually by logging into the websphere application, but in case i want to automate it by powershell , how do i do this. Please suggest
If I understood correctly then you want to power off the list of virtual machines at any given time and then again power it on after some time or at the first place you just want to reboot it directly? Please let me know your requirements so I can comment.
@@SwapnilInfotech sir any insight?
Can you let me know which platform you are using for virtual machines and versions information
Thanks, but how to send an email through service account however we have SMTP server configured on 2 servers.
You just have to create a scheduled task which can run at a particular time and if it finds the service is in a stopped state, it will send an email. You will get more information on the link below
ruclips.net/video/wKB5vexNv6I/видео.html
Yes agree, but i need to send an email through service account not individual alias. I tried and entered mine SMTP server details but it won't work
The script used here in this video is based on an open relay SMTP server so it is not bound to any user account or service account . If you have an open relay SMTP server then you can send it mail from any account. You just have to schedule it in task manager
Can you make a script for windows update for multiple computers
Sure I will check and let you know
@@SwapnilInfotech Thanks and as always you rock, waiting for next video and still I didn't get your number.
@@SwapnilInfotech Any update.