Functions/Get-MDMDeviceOwnership.ps1

function Get-MDMDeviceOwnership(){
    <#
    .SYNOPSIS
         Returns information about the Ownership of the Device.
    .DESCRIPTION
         Returns information about the Ownership of the Device.
         - Corporate Owned
         - Personal Owned
         - Unknown: No information about Ownership found
 
    .EXAMPLE
         Get-MDMDeviceOwnership
    .NOTES
 
    #>

    if((Get-MDMEnrollmentStatus).EnrollmentState -eq 1){
         $CorpOwned = Get-ItemPropertyValue -Path HKLM:\SOFTWARE\Microsoft\Enrollments\Ownership -Name CorpOwned -ErrorAction SilentlyContinue
          switch($CorpOwned){
               0{return "PersonalOwned"}
               1{return "CorporateOwned"}
               $null{return "Unknown"}
          }
     } else {
          Write-Error "Device is not enrolled to MDM."
     }
}
# SIG # Begin signature block
# MIIXxQYJKoZIhvcNAQcCoIIXtjCCF7ICAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUv8VLOSdgrepbclCyPTPpXx1s
# n8mgghL4MIID7jCCA1egAwIBAgIQfpPr+3zGTlnqS5p31Ab8OzANBgkqhkiG9w0B
# AQUFADCBizELMAkGA1UEBhMCWkExFTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTEUMBIG
# A1UEBxMLRHVyYmFudmlsbGUxDzANBgNVBAoTBlRoYXd0ZTEdMBsGA1UECxMUVGhh
# d3RlIENlcnRpZmljYXRpb24xHzAdBgNVBAMTFlRoYXd0ZSBUaW1lc3RhbXBpbmcg
# Q0EwHhcNMTIxMjIxMDAwMDAwWhcNMjAxMjMwMjM1OTU5WjBeMQswCQYDVQQGEwJV
# UzEdMBsGA1UEChMUU3ltYW50ZWMgQ29ycG9yYXRpb24xMDAuBgNVBAMTJ1N5bWFu
# dGVjIFRpbWUgU3RhbXBpbmcgU2VydmljZXMgQ0EgLSBHMjCCASIwDQYJKoZIh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