cpu and memory utilization

Hello, I set alert when a windows CPU reach the treshold.

I would like to execute a powershell script (or any other option) on that server when CPU is hight that collect the process are running that show me who is using CPU and send me by email the list or save in some way so I can analyze when I can.

I use WMI not agent.

based on this can be done for memory as well