Automation

 View Only
  • 1.  Need a script to schedule reboot VM

    Posted Jan 08, 2017 03:57 AM

    Hi All

    Need a script schedule reboot VM's .

    We have 4 SSO servers , 8 inventory,8 web,8vcenter and 8 vum(updatemangager) servers avalible.

    Need to reboot 1st week squence#1 (it follows 4 weeks) 1 SSO server ,2 inventory servers , 2 web,2 vcenter and 2 vum servers .

    reboot the 1st SSO server after check the SSO service is running or not.

    If SSO service is running, then reboot sequence  2 inventory, 2 web,2 vcenter and 2 vum after completed email myself a report squence .

    If SSO service is not running need to reboot the SSO again  nofify through  mail.


    Regards.

    Siva





  • 2.  RE: Need a script to schedule reboot VM

    Posted Jan 08, 2017 08:30 AM

    Can you use Windows Task Scheduler on a station to trigger these scripts?


    A (free) alternative could be to create an appliance with PowerShell and PowerCLI Core, and use that scheduler (crontab).

    But both of these are still alpha code, so not sure if you want to use that in production :smileygrin:



  • 3.  RE: Need a script to schedule reboot VM

    Posted Jan 09, 2017 04:39 PM

    Thanks Lucd.

    Can we get this task using Power shell ?



  • 4.  RE: Need a script to schedule reboot VM

    Posted Jan 09, 2017 05:35 PM

    With powershell you can do anything!

    You can both set up scheduled tasks, and that scheduled task can launch powershell scripts.

    https://blogs.technet.microsoft.com/heyscriptingguy/2015/01/13/use-powershell-to-create-scheduled-tasks/



  • 5.  RE: Need a script to schedule reboot VM

    Posted Jan 10, 2017 07:31 PM

    Thanks Jpsider
    Can we get Power shell script for reboot the hosts and get the service state via Mail.



  • 6.  RE: Need a script to schedule reboot VM

    Posted Jan 11, 2017 01:09 PM

    I can help you get started with some resources sure!

    Here are two community links to different reboots:

    Reboot a VM and wait until tools are running before rebooting the next vm

    check vm power status, restart vm if tools installed else reset vm

    Here is a quick link to get gmail working with Powershell:

    http://www.adminarsenal.com/admin-arsenal-blog/powershell-send-mailmessage-gmail/

    After reviewing I would start to draft your business logic to generate pseudo code, then come back and we can all chip in and help you wrap up any problems you have.



  • 7.  RE: Need a script to schedule reboot VM
    Best Answer

    Posted Jan 16, 2017 07:06 PM

    Thanks Jpsider,

    I finally come up with below power shell Script.

    Is there any short way to reach one. 

    $serverslist = get-content 'C:\temp\Week1.txt'

    $SSOlist=$Serverlist -like "*SSO*"## To pick the SSO in server list##

    $list=$Serverlist -notlike "*SSO*"## To pick the not SSO in server list##

    restart-computer -computername $SSOlist -force

    Sleep 180

    foreach($SSO in $SSOlist)

    {

      FuncCheckService -ServiceName "VMwareIdentityMgmtService" -Server "$SSO"

    }

    function FuncCheckService

    {

        param($ServiceName, $Server)

        $arrService = Get-Service -Name $ServiceName -ComputerName $Server

        if ($arrService.Status -ne "Running")

        {

            $Servicestatus= $arrservice|select machinename,DisplayName,status|sort machinename

      Send-MailMessage @sMail

      Exit

        }

        else

        {

      $Servicestatus=$arrservice|select machinename,DisplayName,status|sort machinename

      Send-MailMessage @sMail

        }

    }

    restart-computer -computername $list -force

    Sleep 180

    $arrservice= Get-Service -Name vimQueryService,vpxd -ComputerName $list|select machinename,DisplayName,status|sort machinename

    Send-MailMessage @sMail

    $Header = @"

    <style>

    BODY {background-color:             #a3dbe7;}

    TABLE {border-width:1px; border-style:solid; border-color:black; border-collapse:collapse;}

    TH, TD {border-width:1px; padding:0px; border-style:solid; border-color:black;}

    </style>

    <title>

    Title of my Report

    </title>

    "@

    $sMail = @{

      From = "from mail id"

      To = "To mail id"

      Subject = "Weekly Reboot Status_"+(get-date).ToString("dd/MM/yyyy")

      BodyAsHtml = $true

      Body = $Servicestatus | ConvertTo-HTML -Head $Header -body "Week1"| Out-String

      SmtpServer = 'Smtp servername'

    }