0

I need help with a script that monitors the upload. The script is intended to prevent crashes of OBS, where OBS simply stops sending data. I have already run this script on several streaming PCs - without problems. But on a new streaming PC it just won't run.

Here is the script for now:

$threshold = 6000
$timer = new-timespan -Seconds 10
$wmi = 0
$count = 0
$clock = [diagnostics.stopwatch]::StartNew()
while ($clock.elapsed -lt $timer){
    $wmi += (Get-WMIObject -Class Win32_PerfFormattedData_Tcpip_NetworkInterface | Select-Object BytesSentPerSec).BytesSentPerSec
    $count++
}

$kbytes = ($wmi/$count)  / 1kb * 8 #to kbit/s


if($kbytes -le $threshold)
{
    Write-Output $kbytes
    Write-Host "Neustart"
    taskkill /f /im obs64.exe
    timeout /t 5
    Start-Process -FilePath "obs64.exe" -WorkingDirectory "C:\Program Files\obs-studio\bin\64bit\" --startstreaming
}
else  
{
    Write-Output $kbytes
    Write-Host "Alles OK"
}

As an error I get this:

Code:

Error when calling the method. [System.Object[]] no method with the name "op_Addition".
In C:\Users\stream1\Desktop\watchdog.ps1:8 Zeichen:5
+     $wmi += (Get-WMIObject -Class Win32_PerfFormattedData_Tcpip_Netwo ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

The program was written for me by someone. Unfortunately, I myself have no experience in programming in Powershell. I would be very grateful for any help. I hope someone can help me. Thanks a lot

Greeting Thomas

"$wmi = 0" --> "$wmi = @()"

Error:

Error calling the method because [System.Object[]] does not contain a method named "op_Division".
In C:\Users\stream1\Desktop\watchdog.ps1:12 character:1
+ $kbytes = ($wmi/$count)  / 1kb * 8 #to kbit/s
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Division:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

0 Answers0