Hi all!
I have a bunch of digital tags with True and False states, mixed up with the Bad digital state. I want to replace the digital state Bad into False.
I've made this powershel script that "in theory", look for the Bad values and replace them into False. Unfortunately, the if statement is not working and my script replace ALL VALUES inside the time range into False, no matter they are already True or False.
# Initializing general variables $piDataArchive = 'server host name' $tagName = 'sinusoid' $st = Get-Date("21/09/2024 19:00:00") $et = Get-Date("22/09/2024 15:20:00") $badVal = "bad" # Bad value $newVal = "false" # Good value # Data Archive conection $con = Connect-PIDataArchive -PIDataArchiveMachineName $piDataArchive # Get PI tag values $tagValues = Get-PIValue -PointName $tagName -StartTime $st -EndTime $et -Connection $con # This part loops through the tag values and replace them for every timestamp foreach ($tagVal in $tagValues) { if ($tagVal.Value = $badVal){ Add-PIValue -PointName $tagName -Time $tagVal.Timestamp -Value $newVal -WriteMode Replace -Connection $con } }
I've tested an if (that is not working), and a "where" clause that is not working eather.
foreach ($tagVal in $tagValues) { Add-PIValue -PointName $tagName -Time $tagVal.Timestamp -Value $newVal -WriteMode Replace -Connection $con | where {($tagVal = $badVal) } }
I dont understand why is not working, or what other option I have to make my script working... May someone helps me with this?
Regards, M.