Below script for your requirement. for some reason I was not able to share the script, try with the article script: Try below one for alternate script.
Get-SPSite http://portal.globalsp.com/sites/sharatha | Get-SPWeb -Limit All | Select Title, URL, ID, ParentWebID | Export-CSV C:\Report.csv -NoTypeInformation
https://www.sharepointdiary.com/2016/02/sharepoint-site-collections-subsites-report.html
Thanks & Regards,