AnsweredAssumed Answered

AFSDK FindPIPoints in Powershell

Question asked by gheorghe.vatui on Dec 21, 2015
Latest reply on Apr 3, 2019 by gregor

Hello PI Square,

 

I was trying to get all tags from a PI Server in Powershell with the latest AFSDK assembly.

 

I was looking at the following example found on the Square but just can't get the query parameter right:

 

PIPointQuery query1 = newPIPointQuery(PICommonPointAttributes.Tag, OSIsoft.AF.Search.AFSearchOperator.Equal, "s*");  
IEnumerable<PIPoint> foundPoints = PIPoint.FindPIPoints(myPIServer, new PIPointQuery[] { query1 });  
foreach (PIPoint currentPIPoint in foundPoints)  
{  
Console.WriteLine(currentPIPoint.Name); 

 

 

I am trying:

 

    $attributesToGet = @("descriptor","engunits")
    $tagQuery1 = New-Object OSIsoft.AF.PI.PIPointQuery("Tag", "Equal", "*");
    $conditions = New-Object OSIsoft.AF.PI.PIPointQuery($tagQuery1)
    $tagObjList = [OSIsoft.AF.PI.PIPoint]::FindPIPoints($PIServerObj, (New-Object OSIsoft.AF.PI.PIPointQuery[]{$tagQuery1}), $attributesToGet)

 

or trying to use a list  :

 

$conditions = @($tagQuery1)
$tagObjList = [OSIsoft.AF.PI.PIPoint]::FindPIPoints($PIServerObj, $conditions, $attributesToGet)

 

OR:

 

    $attributesToGet = @("descriptor","engunits")
    $tagQuery1 = New-Object OSIsoft.AF.PI.PIPointQuery("Tag", "Equal", "*")


    $tagObjList = [OSIsoft.AF.PI.PIPoint]::FindPIPoints($PIServerObj, (New-Object Collections.Generic.IEnumerable[OSIsoft.AF.PI.PIPointQuery] {$tagQuery1}), $attributesToGet)



 

Neither worked so far. Obviously I cannot satisfy the type requirement  "IEnumerable" for the query :

 

Parameters

piServer
Type: OSIsoft.AF.PI.  PIServer
The PIServer to search for the desired PIPoint objects.
query
Type: System.Collections.Generic.  IEnumerablePIPointQuery
A list of PIPoint attribute query filters that are ANDed together to find the desired PIPoint objects. The FindPIPoints(PIServer, String, Boolean, IEnumerable<   String>   , AFSearchTextOption) method can be used to parse a string query and generate this list of queries.
attributeNames (Optional)
Type: System.Collections.Generic.  IEnumerableString
The list of PIPoint attribute names to be loaded from the server as the PIPoint objects are found. The list of PIPoint attribute names can be obtained from the PIPointClass.GetAttributes method or the PICommonPointAttributes class. The GetAttribute(String) method can be used to access the loaded attribute values. If null  , then no attribute values are loaded for the returned PIPoints.

Return Value

Type: IEnumerablePIPoint

Returns the enumerable list of PIPoint objects matching the specified query.

 

Can you share an example of how to do this in Powershell ?  Not any single example in the AFSDK help file is not at all encouraging !...

 

Thank you in advance

Outcomes