dpereira

How to delete values from a range of time in a tag?

Blog Post created by dpereira Employee on Oct 9, 2019

Have you ever wonder if it is possible to delete values from a tag that is inside a range of time? Yes! That is the correct answer. However, you must be thinking that it will be difficult, right? And that is not true. We can do it easily with the PI Powershell Utility!

 

The PI Powershell utility is an extension built on the Windows Powershell utility which can be used to access multiple aspects of the Asset Framework and PI Data Archive. It leverages the extensibility of the AFSDK library to provide structured access to the variety of data stored on the OSISoft PI System.

 

Here is an example of how to How to delete values from a range of time in a tag. You must have the Powershell Tools for the PI System installed.

 

#Select the PI Server Name - Do not use Collective name 
$myPI = Connect-PIDataArchive -PIDataArchiveMachineName <PIDataArchiveAddress>

#Select the tag/pi point name
$tagName = '<TagName>'

#Select the Start Time
[DateTime] $startTime = '2019-08-1 00:00:00'

#Select the End Time
[DateTime] $endTime = '2019-09-1 00:00:00'

#Get all events in the Time Range
$EventsToDelete = Get-PIValue -Connection $myPI -PointName $tagName -StartTime $startTime -EndTime $endTime

#Delete each event that exist in that Time Range
foreach ($Event in $EventsToDelete){Remove-PIValue -Connection $myPI -PointName $tagName -Time $event.TimeStamp}

 

 

Just be sure to substitute:

  • The hostname of your PI Data Archive from <PIDataArchiveAddress> to MyPIHostname
  • The name of the tag from <TagName> to MyTag
  • The start time of the time range to your needs
  • The end time of the time range to your needs

 

Be careful, after running this script you cannot undo the deletion without a backup of the archives that cover that time range!

 

Enjoy!

Outcomes