AnsweredAssumed Answered

Input file in a Powershell script.

Question asked by BrianKHeritage on Dec 7, 2018
Latest reply on Dec 21, 2018 by BrianKHeritage

With the help of Thyagarajan Ramachandran, I've created two Powershell scripts, one to find records with invalid timestamps and another to delete these records.  Both work fine.  I have been asked to add one more feature to the scripts, and that is the ability of the scripts to read in an input file with a list of tags and use this list to either return the bad records for this group of tags or delete the records for this group of tags.  Here is my input file:

 

Bad_Tags_Input.txt

 

which has the following in it:

 

CN_AMB_CI_Cuasi

CN_AMB_III_Moderado

 

The script I came up with for the read is as follows:

 

# connect to PI Data Archive by machine name
$con = Connect-PIDataArchive -PIDataArchiveMachineName OTCENPIDADEV1 -ErrorAction Stop

if ($con.Connected)
{
    # get a collection of PIPoints from an input file
    $PIPoints = Get-Content Bad_Tag_Input.txt

    if ($PIPoints -ne $null)
    {
        foreach ($PIPoint in $PIPoints)
        {
            Get-PIPoint -Name $PIPoint -AllAttributes -Connection $con
            $ProcessTag = $PIPoint
            $ProcessTagName = $ProcessTag.Point.Name
            Write-Output "Now processing $ProcessTagName"
            Get-PIValue -PIPoint $PIPoint -Starttime "01-Nov-2018" -EndTime "01-Dec-2018" | Where-Object { ($_.Timestamp).timeofday -ne "11:00:00"} | Select-Object Timestamp,Value
        }
    }
}

 

Unfortunately, I'm getting errors when I run the scripts.  The error I'm getting is this:

 

Name: CN_AMB_CI_Cuasi; Id: 3274; Server: pi://otcenpidadev1:5450/         {convers, compmin, zero, compmax...}

Now processing

Get-PIValue : Cannot bind parameter 'PIPoint'. Cannot convert the "CN_AMB_CI_Cuasi" value of type "System.String" to type "OSIsoft.PowerShell.PIPoint".

At C:\Users\svr.bhe.ot\Documents\Retrieve_BadA.ps1:17 char:34

+             Get-PIValue -PIPoint $PIPoint -Starttime "01-Nov-2018" -E ...

+                                  ~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Get-PIValue], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,OSIsoft.PowerShell.GetPIValue

 

Name: CN_AMB_III_Moderado; Id: 3275; Server: pi://otcenpidadev1:5450/     {convers, compmin, zero, compmax...}

Now processing

Get-PIValue : Cannot bind parameter 'PIPoint'. Cannot convert the "CN_AMB_III_Moderado" value of type "System.String" to type "OSIsoft.PowerShell.PIPoint".

At C:\Users\svr.bhe.ot\Documents\Retrieve_BadA.ps1:17 char:34

+             Get-PIValue -PIPoint $PIPoint -Starttime "01-Nov-2018" -E ...

+                                  ~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Get-PIValue], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,OSIsoft.PowerShell.GetPIValue

 

It appears that it is retrieving the two tags from the input file but for some reason can't convert the tagname from type "System.String" to type "OSISoft.PowerShell.PIPoint".  Anyone have any idea why?  What am I doing wrong?

Outcomes