AnsweredAssumed Answered

powershell: Why loading OSIsoft.AFSDK?

Question asked by @LCL on May 23, 2017
Latest reply on May 23, 2017 by gachen

Hi everybody,

I'm trying to figure out how to use powershell with PI.

I'm working on the basis of a powershell script which work fine and I have red everywhere that the following statement is important:


However, when I comment this statement, the script is still working. And that make me suspicious...

Why is it still working?

And why if I try to create a  new-object OSIsoft.AF.AFObject (for example) , this one is not created due to "constructor not found".

It's probably nothing but I'm confused and maybe you can help me to clarify this.


Following an extract of the script:

#Serveur AF

$AFServerName ='SERVEUR-AF'

$AFDatabaseName ='AFDB'


#Chargement de la DLL AF SDK

#[reflection.assembly]::LoadWithPartialName("OSIsoft.AFSDK") | Out-Null


#Connection au serveur AF du PISC

$PISystems = new-object OSIsoft.AF.PISystems

$PISystem = $PISystems[$AFServerName]


if($AFDatabaseName){$AFDatabase = $PISystem.Databases[$AFDatabaseName]}


#On recupère la liste des serveurs en fonction du template

$AFelementTemplate = new-object OSIsoft.AF.Asset.AFElementTemplate

$AFelementTemplate = $AFDatabase.ElementTemplates.Item("TemplateUtile")

$AFServerNameList= [OSIsoft.AF.Asset.AFElement]::FindElementsByTemplate($AFDatabase, $null, $AFelementTemplate, $TRUE, 1, 0,  100 )



#On parcourt la liste des serveurs AF

foreach(  $AFServeur in   $AFServerNameList)


    write-output $




It's working on a pi server 2012. Windows server 2012 R2. Powershell V2.0.