Michael Leonard
asked on
need assistance with a powershell script
need some assistance with this script, we need the script to complete each action before moving to the next. It is currently not working as expected.
thanks in advance
$serviceName = "CryptSvc";
$serviceStatus = (get-service "$serviceName").Status;
if ($serviceStatus -eq "Running") {
echo "service is running. Stopping CryptSvc now!";
Stop-Service -Name $servicename;
}
if ($serviceStatus -eq "Stopped") {
echo "CryptSvc is stopped. Starting CryptSvc now!";
Start-Service -Name $servicename;
}
if ($serviceStatus -eq "Running") {
echo "service is running!";
Send-MailMessage -To team@mydomain.com -Subject "Monthly Maintenance Reboot Successful!" -
Body "Monthly Maintenance Reboot completed successfully!
Service has been stopped and started successfully, and service is now running." -SmtpServer
10.1.2.1 -From test@mydomain.com;
}
elseif ($serviceStatus -eq "Stopped"){
echo "service is Running again now!";
Send-MailMessage -To team@mydomain.com -Subject "Monthly Maintenance
Reboot Failed!" -Body "Monthly Maintenance Reboot FAILED!
Service is STOPPED!" -SmtpServer 10.1.2.4 -From
test@mydomain.com;
}
thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER