Automated ping

Created by chatgpt - not working. Access denied. Exec PowerShell doesn't fix it.
 avatar
dacostapiece
powershell
2 years ago
771 B
7
Indexable
# Define the service name and description
$serviceName = "PingService"
$serviceDescription = "Background service that pings IP address 8.8.8.8"

# Define the script block that will be executed by the service
$scriptBlock = {
    while ($true) {
        Test-Connection -ComputerName 8.8.8.8 -Count 1 -Quiet
        Start-Sleep -Seconds 60
    }
}

# Create the service installation parameters
$serviceParams = @{
    Name = $serviceName
    DisplayName = $serviceName
    Description = $serviceDescription
    BinaryPathName = "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File $($MyInvocation.MyCommand.Path)"
    StartupType = "Automatic"
}

# Install the service
New-Service @serviceParams

# Start the service
Start-Service $serviceName
Editor is loading...