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
  • I would take a look at this old post if the automatic recalculation is not what you are looking for: https://pisquare.osisoft.com/s/question/0D51I00004UHiaWSAT/powershell-script-for-backfillrecalculate

    If your database is well designed and depending on what you are trying to do, you might be able to run it just once using option: DeleteExistingDataCalculateDependents.

     

    I seem to spent a large chunk of my time thinking thinking about recalculations and dependencies issues.

     

  • 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?

     

Reply
  • 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?

     

Children
No Data