The SCCM (MECM) sitecode information is stored in WMI, so we can retrieve it using PowerShell.
Here's the command to use:
$SCCMSiteCode = $([WmiClass]"\\localhost\ROOT\ccm:SMS_Client").GetAssignedSite()
$SCCMSiteCode.sSiteCode
If you'd like to know more about the SMS_Client method, please follow this link:
Enjoy ! 😎