6 Replies Latest reply on Dec 8, 2016 4:10 PM by gheorghe.vatui

    Initiate named API or SDK connection from Powershell to PI Data Archive Server

    gheorghe.vatui

      We are interested in developing some tools with Powershell (to start with) to do some administration tasks.

      Observed that Powershell connects to PI using the default powershell.exe PI SDK connection name.

      When script reaches out to PI Data Archive Server for any query, we would like to specify the connection name from the script and equally the connection type ((AF)SDK or the old API).

       

      Is that something that is even remotely possible ?

       

       

      Thank you

        • Re: Initiate named API or SDK connection from Powershell to PI Data Archive Server
          Eugene Lee

          Hi Gheorghe,

           

          You will need to compile the script into an executable using PS2EXE. You can then name your executable as whatever you want.

          PS2EXE : "Convert" PowerShell Scripts to EXE Files

           

          2 of 2 people found this helpful
          • Re: Initiate named API or SDK connection from Powershell to PI Data Archive Server
            gregor

            Hello Gheorge,

             

            I find the answer provided by Eugene Lee helpful but my impression is that this is not what you've been asking for. I however must admit that I am uncertain what exactly you are asking for.

             

            In case you like to know how you would connect to a PI Data Archive host specified by name using OSIsoft.Powershell, please see the snippet below.

             

            $PIServerHost = "<YourPIDataArchiveHostName>"
            $piConnection = Connect-PIDataArchive -PIDataArchiveMachineName $PIServerHost -AuthenticationMethod Windows
            $piConnection
            

             

            Are you possibly intending to use one of OSIsoft's Developer Technologies like AF SDK or PI API instead?

            If this is the case, we will be able to support you with some snippet on how to use AF SDK within PowerShell but we do not support programming against PI API because it's deprecated technology.

            1 of 1 people found this helpful
              • Re: Initiate named API or SDK connection from Powershell to PI Data Archive Server
                gheorghe.vatui

                Hi Gregor,


                Your impression was right - I thought we could have some function in AFSDK that could specify the connection name (for both SDK and API) when connecting to PI.

                I suppose the SDK connection initiated to PI inherits the executable name (Powershell.exe in my case) so I would have to compile the script as Eugene suggested.

                Is there no way of emulating an API connection behavior from AFSDK ? (I am already using PI AFSDK inside Powershell).

                 

                My use case: We have some interfaces that connect to remote systems we cannot control nor access (other that the interface restricted access).
                In one particular case we have a PItoPI interface that pushes some data to remote PIServer and we have lost the list of the tags the interface is loading.
                It was impossible to get a list of all host tags from the logs of the PItoPI (with debug max) because PItoPI truncates the longer tag names before printing them out. And even if I got a destination tag list, there is no way to get the mapping to the source tag. I do not want to go the extra hustle to try narrowing down which pointIDs the specific PItoE connection is reading from our PI Server. 

                Since the PItoPI connection is allowed to read its host tags, if I could just run a Powershell script to connect to the remote PI exactly as the PItoPI API connection, I could query the list of tags and check their mappings.

                 

                Hope this sheds some light into my question.

                  • Re: Initiate named API or SDK connection from Powershell to PI Data Archive Server
                    gachen

                    Hi Gheorghe

                     

                    So in other words you are trying to spoof the API application name (PItoE) to gain access to an existing trust . The application name of SDK applications cannot be set manually by the user, it is always inherited from the executable name. For that matter, it probably won't work out anyway if you use the PS2EXE method, since your application name will end in '.exe', whereas the trust for PItoPI will be for 'PItoE'. You could theoretically write an API application and do this, but spoofing the name to gain access to a trust seems kind of dubious; could you just ask the admins for the remote server for the point list again? Or an alternative authentication method for your script?

                     

                    On a side note, the PowerShell tools which target the PI Data Archive are actually MDA based (tools which target the PI AF server are AFSDK based).