Hi @Prakash Rajan ,
Thanks for using Microsoft Q&A !!
I am able to fetch App Role correctly using your code (see screenshot below)
Can you please check what value you are passing as App Role name ? Instead of passing MyApi.Read.All you need to pass "Read.All" as API Permissions name.
$appRoleName = 'Read.All'
Please check if that's not the case and you are still having issues.
Thanks
Saurabh
----------
Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.