Functions/Get-MDMPSScriptStatus.ps1

function Get-MDMPSScriptStatus(){
    <#
    .SYNOPSIS
         Returns information about the execution of PowerShell Scripts deployed with Intune.
    .DESCRIPTION
         Returns information about the execution of PowerShell Scripts deployed with Intune.
 
    .EXAMPLE
         Get-MDMPSScriptStatus
    .NOTES
 
    #>

    $PSStatus = @()
    if((Get-MDMEnrollmentStatus).EnrollmentState -eq 1){
        $Users = Get-ChildItem HKLM:\SOFTWARE\Microsoft\IntuneManagementExtension\Policies\ -ErrorAction SilentlyContinue
        foreach($user in $users){
            $Scripts = Get-ChildItem "$($user.PSPath)"
            foreach($Script in $Scripts){
                $Script = Get-ItemProperty $Script.PSPath
                $PSStatus += $App
            }
        }
    } else {
        Write-Error "Device is not enrolled to MDM."
    }
    return $PSStatus
}
# SIG # Begin signature block
# MIINHQYJKoZIhvcNAQcCoIINDjCCDQoCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUh4QN6XVZkV5Fp65FaBBMA5N/
# o6ygggpfMIIFJzCCBA+gAwIBAgIQCU9NEi6qCZCLwI+uzRfDqjANBgkqhkiG9w0B
# AQsFADByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD
# VQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFz
# c3VyZWQgSUQgQ29kZSBTaWduaW5nIENBMB4XDTE2MDYwNjAwMDAwMFoXDTE5MDYx
# MTEyMDAwMFowZDELMAkGA1UEBhMCQ0gxEjAQBgNVBAgTCVNvbG90aHVybjERMA8G
# A1UEBwwIRMOkbmlrZW4xFjAUBgNVBAoTDWJhc2VWSVNJT04gQUcxFjAUBgNVBAMT
# DWJhc2VWSVNJT04gQUcwggEiMA0GCSqGSIb3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