Hi @NehaBameta-3476 ,
Thanks for posting your query in Q&A.
You can get the list of tenants using the Rest API List method and then invoke the rest api from powershell using the Invoke-RestMethod command. This powershell script should list all tenants. Once the powershell script is working on your local machine, you can deploy the script to the Azure powershell functions. Alternatively, you can directly develop the script in the Azure functions portal.
Hope this helps! Feel free to reach out to me if you have any queries or concerns.
Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.