Powershell script for Backfill/Recalculate

Hi All,

 

I'm trying to create a PS script (I don't have much knowledge of programming but I'm trying and testing out, so far nothing worked) for backfilling 3 different analysis during a time range that will run everyday using Windows Task Scheduler. The analysis are interdependent, so the first analysis have to be backfill first than the second and then the third. I'm thinking to filter the analysis by the analysis category

 

Have ever anyone done that before? Does anyone has a script that they can share?

 

Thanks!!!!

Parents Reply Children
  • The version used does not support automatic recalculation and they don't want to upgrade.

    Also, the attribute that can be added more data if someone forget on the time it is a table lookup attribute, which does not recognizes as out of order data, so automatic recalculation would not work as well

  • I did take a look on that,

     

    I come up with something that run but when I put the foreach search elements to filter that part does not work.

     

    Like param(

    [Parameter(Mandatory=$true)]

    [string]$PISystem,

    [Parameter(Mandatory=$true)]

    [string]$Database,

    [string]$Query = ""

    [string]$Start = "*-1d",

    [string]$End = "*",

    [ValidateSet('DeleteExistingData','FillDataGaps')]

    [string]$Option = 'DeleteExistingData'

    )

    # load AFSDK

    [Reflection.Assembly]::LoadWithPartialName("OSIsoft.AFSDK") | out-null

    $systems = new-object OSIsoft.AF.PISystems

    $system = $systems[$PISystem]

    $db = $system.Databases[$Database]

     

    Element

    $SiteOperation_Element = $DB.Elements["SiteName"].Elements["SiteCode"].Elements["SiteOperation"]

    foreach($element in $SiteOperation_Element.Elements)

    {

      Analysis

    function GetAnalysis($Query)

    {

    $analysisSearch = new-object OSIsoft.AF.Search.AFAnalysisSearch $db, "", $Query

    $count = $analysisSearch.GetTotalCount()

    if ($count -gt 0) {

      $timeRange = new-object OSIsoft.AF.Time.AFTimeRange $Start, $End

     $analyses = $analysisSearch.FindAnalyses()

     [void]$system.AnalysisService.QueueCalculation($analyses, $timeRange, $Option)

     Write-Host "Queued $count analyses for recalculation from $($timeRange.StartTime) to $($timeRange.EndTime) using option $option"

    } else {

    Write-Host "No analyses found matching '$Query' in $Database" }

    }

     

    $Query = "Analysis1"

    GetAnalysis $Query

    $Query = "Analysis2"

    GetAnalysis $Query

    $Query = "Analysis3"

    GetAnalysis $Query

     

    If I added the part in bold it does not work as I wanted, If I removed, the script worked fine, but I need to filter on the element path.

     

    Do you know what I am missing? What should I change for the filter on the elements to work?