Edit - Below will work only for SP on premises environment.
I think you can use Pure Powershell command.
Get-SPSite -Identity "121321-12312-12312-1231231"
Identity parameter takes url or GUID, below is text from microsoft documentation
Specifies the URL or GUID of the site collection to get.
The type must be a valid URL, in the form, https://...
The Microsoft Graph can provide you the information about the site collection. See the paragraph Note for existing SharePoint developers and especially the last example.
The endpoint URL for your use case would then be
Resulting URL for tenant mytenant.sharepoint.com and site collection ...
Here's a way to do it: get the SiteUsers collection, and then filter that by the presence of the string #ext# in the LoginName property of each user.
The below sample assumes you're pointing to your CSOM library
# organise session etc.
$siteURL = "https://yourtenant.sharepoint.com/sites/yourcollection/yoursite"
$username = "your-username@yourtenant....