Enable scheduled task on several computers

# Update the list of computers
$ComputerNames = @("computer1", "computer2", "computer3", "computer4")

# Update with the name of the scheduled task you want to enable
$TaskName = "WindowsUpdate"

# Script block to enable the scheduled task
$scriptBlock = {
    param ($TaskName)
    try {
        # Enable the scheduled task
        Enable-ScheduledTask -TaskName $TaskName -ErrorAction Stop
        Write-Output "Task '$TaskName' enabled successfully on $env:COMPUTERNAME."
    }
    catch {
        Write-Output "Failed to enable task '$TaskName' on $env:COMPUTERNAME. Error: $_"
    }
}

# Execute the script block on each computer
foreach ($Computer in $ComputerNames) {
    Invoke-Command -ComputerName $Computer -ScriptBlock $scriptBlock -ArgumentList $TaskName -ErrorAction Continue
}