phsutter

PI AF SDK in Powershell

Discussion created by phsutter Champion on Feb 12, 2014
Latest reply on Jul 3, 2014 by Paurav Joshi

Hello guys

 

I started using PI AF SDK in Powershell, but now run into a problem. A simple script demonstrates my problem:

 
# Add a reference to the PI AF assemblies. Needed for PI AF calls further down
Add-Type -Path ($env:PIHOME + "\AF\PublicAssemblies\4.0\OSIsoft.AFSDK.dll")
$newServers=New-Object OSIsoft.AF.PI.PIServers
($newServers).Name

 My script runs fine in the Powershell ISE and creates a list of all known PI server names. However if I run the same script with Powershell from the command line I get the following error:

 

C:\Users\xxx>powershell.exe -file Documents\servers.ps1
New-Object : Exception calling ".ctor" with "0" argument(s): "Could not load
file or assembly 'Microsoft.PowerShell.Commands.Utility' or one of its
dependencies. The system cannot find the file specified."
At C:\Users\xxx\Documents\servers.ps1:5 char:13
+ $newServers=New-Object OSIsoft.AF.PI.PIServers
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvoca
tionException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power
Shell.Commands.NewObjectCommand

 

Powershell is running in STA mode, executionpolicy is unrestricted. What could be the problem? My goal is to finally run a script from the task scheduler, but so far this fails immediately when trying to create the first object.

 

Thanks for your feedback!

 

Philipp

Outcomes