2 Replies Latest reply on Dec 7, 2018 6:14 PM by BrianKHeritage

    Input file in a Powershell script.

    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?

        • Re: Input file in a Powershell script.
          Lal_Babu_Shaik

          Hi Brain

           

          Modified the script: Error occuried due to Get-PIValue where it takes -PointName rather than -PIPoint. Highlighted in bold for reference.

           

          $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

                      (Get-PIPoint  -Name $PIPoint -attributes tag,datatype,description -Connection $con).attributes|select values |Format-list

                      $ProcessTag = $PIPoint

                      $ProcessTagName = $ProcessTag.Point.Name

                      Write-Output "Now processing $ProcessTagName"

                      Write-Output $PIPoint

                      #Get-PIValue -PIPoint $PIPoint -Connection $con -Starttime "07-Dec-2018" -EndTime "08-Dec-2018" | Select TimeStamp,Value

                      Get-PIValue -PointName $PIPoint -Connection $con -Starttime "01-Nov-2018" -EndTime "01-Dec-2018" | Where-Object { ($_.Timestamp).timeofday -ne "11:00:00"}  | Select-Object TimeStamp, Value

                  }

              }

          }

           

          Sample output :

           

          1 of 1 people found this helpful