11 Replies Latest reply on Jan 16, 2018 5:55 AM by DivyaGowda

    How to delete bad values for number of tags using Power shell script.

    DivyaGowda

      Hi All,

       

      I am trying to delete bad values for number of tags using power shell script.

      Can anyone please help me with the script.

       

      am trying below script.

       

      $con=Connect-PIDataArchive -PIDataArchiveMachineName Pimachinename

      Select-Object -Property TimeStamp, Value

      Get-PIValue -PIPoint -AllAttributes $pt -StartTime "2-Jan-2018 10:47:00" -EndTime "3-Jan-2018 05:15:00" | where -Pointsource:=abc  | where-Object { ($_.Value.State -eq 307) -and ($_.Value.StateSet -eq 0) } |Select TimeStamp, Value

      Remove-PIValue -Event (Get-PIValue -pointsource:=abc $pt -StartTime "2-Jan-2018 10:47:00" -EndTime "3-Jan-2018 05:15:00" | Where-Object { ($_.Value.State -eq 307) -and ($_.Value.StateSet -eq 0) }) -Connection $con

       

      Regards,

      Divya

        • Re: How to delete bad values for number of tags using Power shell script.
          John Messinger

          Hi Divya,

           

          So I modified your script slightly as follows:

           

          $con = Connect-PIDataArchive -PIDataArchiveMachineName 'PI-DEVELOPMENT'
          $pts = Get-PIPoint -WhereClause 'pointsource:=abc' -Connection $con
          foreach ($pt in $pts)
          {
              Remove-PIValue -Event (Get-PIValue -PIPoint $pt -StartTime "10-Jan-2018" -EndTime "10-Jan-2018 17:15:00" | Where-Object { ($_.Value.State -eq 307) -and ($_.Value.StateSet -eq 0) }) -Connection $con
          }
          

           

          This worked fine for me. In your script above, lines 2 and 3 seem superfluous, thus I removed them from my script version. Note also that Get-PIPoint is called first, and then the returned list of points is looped through to remove the bad events.

           

          John

          5 of 5 people found this helpful
            • Re: How to delete bad values for number of tags using Power shell script.
              DivyaGowda

              Hi Jhon,

               

              Thanks for the script.

               

              am still facing issues with this, am using 2016 PI version. i have tried some scripts but it work.

              am getting below error. can you please let me know what can be changed.

              I have tried writing the script instead of copying i was not able to get the Event parameter.

               

              "Remove-PIValue : Cannot validate argument on parameter 'Event'. The argument is null or empty."

               

              Thanks,

              Divya

                • Re: How to delete bad values for number of tags using Power shell script.
                  John Messinger

                  Hi Divya,

                   

                  OK, a couple of things. Can you please confirm what version of the PowerShell Tools for the PI System your are running, using the following command:

                   

                  (Get-Module OSIsoft.PowerShell).Version
                  

                   

                  Secondly, can you please post the complete script you are using that generates this error.

                   

                  Cheers,

                  John

                    • Re: How to delete bad values for number of tags using Power shell script.
                      DivyaGowda

                      Hi Jhon,

                       

                      PS version is 5.0.10586.117

                       

                       

                      Below is the error which am getting when i run PS.

                       

                      Remove-PIValue : Cannot validate argument on parameter 'Event'. The argument is null or empty. Provide an argument that is not

                      null or empty, and then try the command again.

                      At F:\Program Files\PI\adm\Divyatest1.ps1:5 char:23

                      + ... alue -Event (Get-PIValue -PIPoint $pt -StartTime "02-Jan-2018 10:43:0 ...

                      +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                          + CategoryInfo          : InvalidData: (:) [Remove-PIValue], ParameterBindingValidationException

                          + FullyQualifiedErrorId : ParameterArgumentValidationError,OSIsoft.PowerShell.RemovePIValue

                       

                      Thanks,

                      Divya

                        • Re: How to delete bad values for number of tags using Power shell script.
                          John Messinger

                          Hi Divya,

                           

                          Thanks for that, however unfortunately you haven't actually provided either of the pieces of information that I asked for. I asked for the PowerShell Tools for the PI System module version, NOT the PowerShell version. Please run the following commands to return this information:

                           

                           

                          Secondly, I asked for a copy of the complete script you were executing, not the complete text of the error received.

                           

                          If you can post these two pieces of information then we can proceed with debugging the error you are getting.

                           

                          Regards,

                          John

                            • Re: How to delete bad values for number of tags using Power shell script.
                              DivyaGowda

                              Hi John,

                               

                              Sorry  for not giving complete info which you were asking for.

                              Please find the below screen shots for  PS version for PI.

                               

                              am using the same script which you have provided. please find below for the same.

                               

                              $con = Connect-PIDataArchive -PIDataArchiveMachineName 'machinename'

                              $pts = Get-PIPoint -WhereClause 'pointsource:=R' -Connection $con

                              foreach ($pt in $pts)

                              {

                              Remove-PIValue -Event (Get-PIValue -PIPoint $pt -StartTime "02-Jan-2018 10:43:00" -EndTime "02-Jan-2018 13:00:00" | Where-Object { ($_.Value.State -eq 321) -and ($_.Value.StateSet -eq 0) }) -Connection $con

                              }

                               

                              Thanks,

                              Divya

                                • Re: How to delete bad values for number of tags using Power shell script.
                                  John Messinger

                                  OK, I see what the issue is here for you. As you are using an older version of PowerShell Tools for the PI System than I am, the Get-PIValue cmdlet in your version doesn't accept a PIPoint object as one of the parameters. You will need to modify your script to pass in either the PointName or PointId instead. This also means that you will need to slightly modify your Get-Point query to include some specific attributes (either tagname or pointid) to be returned. I would suggest the following modification to your script:

                                   

                                  $con = Connect-PIDataArchive -PIDataArchiveMachineName 'machinename'
                                  $pts = Get-PIPoint -WhereClause 'pointsource:=R' -Connection $con -Attributes tag,pointid
                                  foreach ($pt in $pts) 
                                  { 
                                      Remove-PIValue -Event (Get-PIValue -PointName $pt.Point.Name -StartTime -StartTime "02-Jan-2018 10:43:00" -EndTime "02-Jan-2018 13:00:00" | Where-Object { ($_.Value.State -eq 307) -and ($_.Value.StateSet -eq 0) }) -Connection $con 
                                  }
                                  

                                   

                                  John