I believe one of the problems is the amount of possible parameters one could use with Find-AFEventFrame.

Please enclose strings into double-quotes e.g. when specifying a NameFilter.

As far as I can see, the Element name is not included with the Event Frame name. Hence using the Element name as NameFilter will likely cause an empty result set being returned. You can use the Element (object) as input for Find-AFEventFrame. To Get an Element, Get-AFElement comes in handy but this method does not crawl the entire Element tree but only the children of the object passed.

If you like to stick with OSIsoft.PowerShell and use the Element as the filter for EventFrames, than the only option is to "browse" from the root to the Element EventFrames belong to.

There are however other options like using AF SDK within PowerShell or just using the NameFilter. Before suggesting those, I would like to get a better understanding about which search criteria you like to apply.

Can you please set up a search in PI System Explorer and take a screenshot of the dialog?

I wouldn't know of much resources for OSIsoft.PowerShell module at current time. Please allow me to ask if you are new to PowerShell in general or if you are just struggling with OSIsoft.PowerShell?

When I started creating the first PowerShell scripts, I read everywhere how powerful PowerShell is but found it not as intuitive right away. My personal takeaway with PowerShell is that there is a learning curve as well. In case your first steps with OSIsoft.PowerShell are your first steps with PowerShell at all, you may want to exercise one of the almost countless tutorials available in the internet before looking into OSIsoft.PowerShell.

If you are experienced with PowerShell but find it hard to use OSIsoft.PowerShell module and am missing examples, we will be happy to support you.

Thanks for your info, this gives me a better insight about Osisoft.Powershell. Although I am a beginner with powershell, I start to learn how to deal with it. The most important reason for now is to be able to remove a large amount of eventframes from the database for particular elements. Now I created the following script that follows the AF-hierarchy and this works fine, however very slow if you need to remove several milions EF's. Also I have to change the script for another element.

"AF SDK with powershell" I did not look at, but I will dive into that too...

Maybe it is better to use a direct SQL-statement to remove large amounts of eventframes. But in that case I need to know the exact table-hierachy for removing an eventframe. Or better, a script for remove an eventframe, because this info is stored in several tables... What is your opinion about this?

Deleting millions of EventFrames sounds like a tedious and time consuming task. What went wrong?

Because PI OLEDB Enterprise provides you with read-only access, I assume you refer to deleting from PIFD database directly. I like to discourage you from doing this because we don't support direct access to the PIFD database.

Have you looked into using PI System Explorer or PI Builder add-in to MS Excel? The search for EventFrames should be pretty complete and hence convenient. The delete operation itself will still take time.

In fact nothing went wrong..., but we did not realized we were logging such an amount of eventframes. In this case it was the cocoa-presses, total number is 20 machines, every cycle takes avg 5 minutes, every cycle generates minimal 10 eventframes (10 steps) resulta is more then 20 milj. EF's. per year. This is too much data for us at the moment, it slows down the reports and it really does not add so much additional info.

We changed the logging into once per day per product type: this is more then 20 times less. With this info we still have enough information we need about the press-cycles.

But we already stored more then 1 year EF's, and this amount stands in the way so I am deleting them with the script. First all EF's for those assets are deleted, and after that we create with backfill for those assets the EF's again, but then based on the "once per day per producttype"- concept.It will take some time, I expect untill the end of this month...

If I understand correctly, you like to purge all EventFrames for a particular database. Is this the case? Let's see if we can buy you some time.

I have again used the Pump Demo database mentioned earlier. The first thing which I did was stopping all Analysis generating EventFrames.

I than merged some of your PowerShell snippets with mine. The resulting script doesn't care about AFElements but just for the AFDatabase. It takes the EventFrames between 1-Jan-2016 and 9-Nov-2017 in chunks of 100 and deletes them 1-by-1. It took less than 5 minutes to wipe the 7311 EventFrames in my personal Pump Demo database. The script may run for several hours in your case but should do the job.

The AFDiag utility has a /DelEF flag that allows you to bulk delete event frames.

From the user guide:

/DelEF: Deletes event frames from the PI AF SQL Server database with an end time before the date specified in month/day/year format (for example, /DelEF:"11/24/2016").Since this can be a lengthy operation, the command will be executed asynchronously.

Note: You can only specify a time, so it is not possible to filter by name, template, etc. It deletes all event frames that end before the time specified

Reading the whole thread, this does not appear like it would work for you in this case, but you may find it useful for other bulk deletions of EF's