Closed FSGermany closed 1 year ago
On one line you have
# The following sets the variable $_myNotificationTrigger_1 to a string
$_myNotificationTrigger_1="NotificationTriggerOn"
And then you have
# The following sets $_myNotificationTrigger_1 to either a collection of NotificationTrigger objects or another string
try{$_myNotificationTrigger_1 = ($_Sensors.item($i) | Get-NotificationTrigger)}
catch{$_myNotificationTrigger_1="Fehler beim auslesen" }
and then on another line you have
# The following calls the "item" method on $_myNotificationTrigger_1 - which is a string
$_myNotificationTrigger_1.item($j).Name
Sometimes $_myNotificationTrigger_1
is a string, sometimes it is an array. When it's a string, strings don't have an item
method, hence you are getting this error.
I would also note you are making things harder on yourself by casting lists to ArrayList
and using the item
method. You can simply use lists as follows
# Declaring an empty list
$myList = @()
# Adding an item to our list
$myList += 3
# Accessing the item in our list
$myList[0]
Hello lordmilko,
thank you for your advice. I will rewrite the script and try again.
What's going on?
Hello,
we have problems in export specific sensor information with Notification Triggers from one server. The server has an sensor "SNMP HPE ProLiant system status" with several threshold triggers for different channels. All threshold triggers have Notification Trigges for NotificationTriggerOn and Off. When we execute our script we've got an error that [System.String] doesn't contain a method with the name "item".
We are using servers from the same manufacturer and the same generation but only one is making problems. We have already deleted the sensor in PRTG and add a new one, but the problem still exists.
Here is our script:
We are using the following versions:
PSVersion : 5.1.17763.2931 PSEdition : Desktop OS : Microsoft Windows Server 2019 Standard PrtgAPIVersion : 0.9.18 Culture : de-DE CLRVersion : .NET Framework 4.8 (528049) PrtgVersion : 22.4.80.1553 PrtgLanguage : german.lng
What are we doing wrong?
Due Dilligance