Hello Ma, Yu Qing1, welcome to Microsoft Q&A forum.
Thanks for coming back and sharing what works.
Disabling power management on Ethernet adapters prevents Windows from turning off the adapter to save power, which can cause network disconnections—critical for projects requiring stable connections or automated scripts. Your PowerShell script works because it targets all physical Ethernet adapters by interface type (6 = Ethernet) rather than by adapter name, which can vary between systems. The loop ensures every Ethernet adapter gets power management disabled, preventing the "allow computer to turn off device" setting from re-enabling.
This is a solid approach and will be helpful for others facing the same issue. I really appreciate you posting the solution.