DEV Community

redhcp
redhcp

Posted on • Edited on

2 1

Handler common Activities Tasks VMs

These scripts help reduce execution times and can be done remotely and to multiple VMs at the same time.

Task for handle services,process,scheduletask,etc with powershell

$computers = @(
        'COMPUTER_NAME_1',
        'COMPUTER_NAME_2'
 )
 foreach ($computer in $computers) {

Write-Host "ComputerName: $env:COMPUTERNAME ($(Get-Date -Format MM/dd/yyyy)) "  -foregroundcolor "green"

#STOP PROCESS PID
   #  Invoke-Command -Computername $computer -scriptblock {stop-precess -id 123 } #number PID

#STOP SERVICE
  #  Invoke-Command -Computername $computer -scriptblock {stop-service SERVICE-NAME -force}

#Validate Service 
    # Invoke-Command -Computername $computer -scriptblock {get-service SERVICE-NAME}

#Start Service
    # Invoke-Command -Computername $computer -scriptblock {start-service SERVICE-NAME }

#Disable TASK
    # Invoke-Command -Computername $computer -scriptblock {Disable-ScheduledTask -TaskName TASKNAME}

#Enable TASK
    # Invoke-Command -Computername $computer -scriptblock {Enable-ScheduledTask -TaskName TASKNAME}

#Start TASK
    # Invoke-Command -Computername $computer -scriptblock {Start-ScheduledTask -TaskName TASKNAME}

#VALIDATE TASK
  Invoke-Command -Computername $computer -scriptblock {Get-ScheduledTask -TaskName "TASKNAME"}

#Get TASK by status Values: Running / Ready / Disabled / Queued / Unknown
 #Invoke-Command -Computername $computer -scriptblock {Get-ScheduledTask | where{$_.State -eq "Ready"}}

}

Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs