Delete values using PowerShell

Hello,

 

We need to delete particular values appearing at 00:00:01 every day for a tag. Rest of the values must remain. We created attached PowerShell script to achieve the same, but getting a prompt for 'Connection:' while executing.

cmdlet Get-PIPoint at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
Connection:

Could you please suggest what do we need to enter against this prompt? Or could there be some other issue?

 

Thanks,

Sujoy Halder

 

PowerShell code:

# Load the OSIsoft PowerShell Extensions
Import-Module OSIsoft.PowerShell


# Connect to the PI Data Archive by specifying its name
$piDataArchiveName = "PI-Global"
Connect-PIDataArchive -PIDataArchiveMachineName $piDataArchiveName

# Define the start and end dates
$startDate = Get-Date "10 June 2024 00:00:01"
$endDate = Get-Date "11 June 2024 00:00:01"

# Define the tag name
$tagName = 'ESUM_NV_all_Vorhersage_1D'

# Retrieve the PIPoint object for the tag name
$piPoint = Get-PIPoint -Name $tagName

# Loop through each day in the range and remove the value at 00:00:01
while ($startDate -le $endDate) {
    # Define the specific time for the value to be deleted
    $specificTime = $startDate.Date.AddSeconds(1) # This ensures the time is 00:00:01

    # Get the PI value for the tag at the specified timestamp using the PIPoint object
    $piValue = Get-PIValue -PIPoint $piPoint -Time $specificTime

    # Check if the value exists before attempting to remove it
    if ($piValue -ne $null) {
        # Remove the PI value
        Remove-PIValue -PIValue $piValue
        Write-Host "Deleted value for $tagName on $($specificTime)"
    }
    else {
        Write-Host "No value found for $tagName on $($specificTime)"
    }

    # Move to the next day
    $startDate = $startDate.AddDays(1)
}

Write-Host "Completed deletion of values for the specified date range."

 

  • GetPIValue Class (aveva.com)

    RemovePIValue Class (aveva.com)

     

    You need to specify the connection. Review the examples on the documentation.

    $con = Connect-PIDataArchive -PIDataArchiveMachineName $piDataArchiveName
    
    $piPoint = Get-PIPoint -Name $tagName -Connection $con
    
    foreach ... {
      $piValue = Get-PIValue -PIPoint $piPoint -Time $specificTime -Connection $con
    
      Remove-PIValue -PIValue $piValue -Connection $con
    }

     

  • Thanks for your answer. I was able to make it work.

     

    # Load the OSIsoft PowerShell Extensions
    Import-Module OSIsoft.PowerShell
    
    
    # Connect to the PI Data Archive by specifying its name
    $piDataArchiveName = "PI-Global"
    # Connect to the PI Data Archive and store the connection in a variable
    $piConnection = Connect-PIDataArchive -PIDataArchiveMachineName $piDataArchiveName
    
    # Use the stored connection for the Get-PIPoint cmdlet
    
    
    # Define the start and end dates
    $startDate = Get-Date "10 June 2024 00:00:01"
    $endDate = Get-Date "15 February 2025 00:00:01"
    
    # Define the tag name
    $tagName = 'ESUM_NV_all_Vorhersage_1D'
    
    # Retrieve the PIPoint object for the tag name
    $piPoint = Get-PIPoint -Name $tagName -Connection $piConnection
    
    # Loop through each day in the range and remove the value at 00:00:01
    while ($startDate -le $endDate) {
        # Define the specific time for the value to be deleted
        $specificTime = $startDate.Date.AddSeconds(1) # This ensures the time is 00:00:01
    
        # Get the PI value for the tag at the specified timestamp using the PIPoint object
        $piValue = Get-PIValue -PIPoint $piPoint -Time $specificTime
    
        # Check if the value exists before attempting to remove it
        if ($piValue -ne $null) {
        # Remove the PI value using the PIPoint object and the specific time
        Remove-PIValue -PIPoint $piPoint -Time $specificTime
        Write-Host "Deleted value for $tagName on $($specificTime)"
    }
    else {
        Write-Host "No value found for $tagName on $($specificTime)"
        }
    
        # Move to the next day
        $startDate = $startDate.AddDays(1)
    }
    
    Write-Host "Completed deletion of values for the specified date range."