4 Replies Latest reply on Jun 1, 2018 3:40 PM by ChrisGard

    Delete records from multiple tags

    ChrisGard

      I have a date and time stamp with a value of I/O Timeout for a bunch of tags that were updated by the interface when it lost connection. The business has since decided they do not want this to display as a value. I have updated the interface not to send that when the connection is lost but now I need to remove the records.

      Is there a way to run a script or command passing the date and timestamp to remove that record from multiple tags rather than using Archive Editor on each tag?

        • Re: Delete records from multiple tags
          rschmitz

          Hi Chris,

           

          you have a couple of options available to you for scripting the deletion of these events. I would personally recommend using the PowerShell tools for doing this. I would recommend taking a look at KB3065OSI8, specifically nder the section "Deleting archive events with a specific Digital State value within a time range"

           

          Cheers,

          Rob

          3 of 3 people found this helpful
            • Re: Delete records from multiple tags
              ChrisGard

              Hi Rob,

              Thank you for the fast response.

               

              I was looking at the options here and this looks like the best option for me.  I already know the Pointsource and the date timestamp 31-May-18 10:57:47 I/O Timeout

              $conn = Connect-PIDataArchive -PIDataArchiveMachineName myserver

              Get-PIPoint -Connection $conn -WhereClause 'pointsource:=R' | % { Get-PIValue -PIPoint $_ -StartTime '2016-01-08' -EndTime '2016 01-09' | Remove-PIValue -Connection $conn }

               

              My followup question is: Do I just place the 31-May-18 10:57:47 for the start and end time?

               

              thanks

              Chris.

                • Re: Delete records from multiple tags
                  rschmitz

                  So you have two options here, you could either:

                  1. Use the "-Time" parameter on the Get-PIValue (rather than -StartTime and -EndTime) to get the value for a single point in time.

                  2. You could use filter with the time range to ensure you only get values where there was a system digital state for I/OTimeout (which happens to be state 246). See the below:

                   

                  $conn=Connect-PIDataArchive -PIDataArchiveMachineName PISRV1
                  Select-Object -Property TimeStamp, Value
                  Get-PIPoint -Connection $conn -WhereClause 'pointsource:=OPC' | % { Get-PIValue -PIPoint $_ -StartTime "20-Apr-16 13:00:00" -EndTime "20-Apr-16 13:15:00" | Where-Object { ($_.Value.State -eq 246) -and ($_.Value.StateSet -eq 0) } | Select TimeStamp, Value }
                  
                  

                   

                  You can use the above to grab all of the points with this point source and an "I/O Timeout" value in the time range (in case any are off by a second or something you wouldn't want to miss them by specifying an exact second). Then once you confirm you have all the right points, you could pipe the output to a Remove-PIValue commandlet.

                   

                  --Rob

                  1 of 1 people found this helpful
                  • Re: Delete records from multiple tags
                    ChrisGard

                    thank you Rob,  The answer you provided helped greatly.

                     

                    Here is the commands I used in PowerShell:

                    $conn = Connect-PIDataArchive -PIDataArchiveMachineName myserver

                    Get-PIPoint -AllAttributes -Connection $conn -WhereClause 'pointsource:=RDBMSLAB' | % { Get-PIValue -PIPoint $_ -StartTime '2018-05-31 10:57:47' -EndTime '2018-05-31 10:57:47' | Remove-PIValue -Connection $conn }

                     

                    This cleaned up the data nicely.