To download all PS files stored in Intune:


Use Powershell to download a list of all scripts being stored endpoint manager/Intune - this is helpful when you no longer have the scripts that were uploaded and you need to make changes.


1 - Ensure that you have the latest Intune Powershell SDK installed:

                 From PS Admin:  


Install-Module -Name Microsoft.Graph.Intune


2 -  Consent to the MS Graphic API   (this should only need to be done once more tenant)


Connect-MSGraph -AdminConsent


3 - Connect to MS Graph


Connect-MSGraph


4 - Run GET-DeviceManagement Script


You will need to download / create a PS script to perform this function - the one attached here was downloaded from Github on 6/28/22 - mc (file attached to this article)


Intune/Get-DeviceManagementScripts.ps1 at master · okieselbach/Intune · GitHub:





####################################################

#region Initialization code



$m=Get-Module-Name Microsoft.Graph.Intune -ListAvailable

if (-not$m)

{

    Install-Module NuGet -Force

    Install-Module Microsoft.Graph.Intune

}

Import-Module Microsoft.Graph.Intune -Global



#endregion



####################################################



FunctionGet-DeviceManagementScripts(){

<#

.SYNOPSIS

Get all or individual Intune PowerShell scripts and save them in specified folder.

 

.DESCRIPTION

The Get-DeviceManagementScripts cmdlet downloads all or individual PowerShell scripts from Intune to a specified folder.

Initial Author: Oliver Kieselbach (oliverkieselbach.com)

The script is provided "AS IS" with no warranties.

 

.PARAMETER FolderPath

The folder where the script(s) are saved.



.PARAMETER FileName

An optional parameter to specify an explicit PowerShell script to download.



.EXAMPLE

Download all Intune PowerShell scripts to the specified folder



Get-DeviceManagementScripts -FolderPath C:\temp 



.EXAMPLE

Download an individual PowerShell script to the specified folder



Get-DeviceManagementScripts -FolderPath C:\temp -FileName myScript.ps1



#>



    [CmdletBinding()]

    Param(

        [Parameter(Mandatory=$true)][String] $FolderPath,

        [Parameter(Mandatory=$false)][String] $FileName

    )



    $graphApiVersion="Beta"

    $graphUrl="https://graph.microsoft.com/$graphApiVersion"



    $result=Invoke-MSGraphRequest-Url "$graphUrl/deviceManagement/deviceManagementScripts"-HttpMethod GET



    if ($FileName){

        $scriptIds=$result.value|Select-Object id,fileName |Where-Object-Property fileName -eq$FileName

        $script=Invoke-MSGraphRequest-Url "$graphUrl/deviceManagement/deviceManagementScripts/$($scriptId.id)"-HttpMethod GET

        [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($($script.scriptContent))) |Out-File-Encoding ASCII -FilePath $(Join-Path$FolderPath$($script.fileName))

    }

    else{

        $scriptIds=$result.value|Select-Object id,fileName

        foreach($scriptIdin$scriptIds){

            $script=Invoke-MSGraphRequest-Url "$graphUrl/deviceManagement/deviceManagementScripts/$($scriptId.id)"-HttpMethod GET

            [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($($script.scriptContent))) |Out-File-Encoding ASCII -FilePath $(Join-Path$FolderPath$($script.fileName))

        }

    }

}



Connect-MSGraph|Out-Null



Get-DeviceManagementScripts-FolderPath C:\temp

#Get-DeviceManagementScripts -FolderPath C:\temp -FileName myScript.ps1



5 - Run the script - the variables set in the script will automatically use c:\temp as the download location (or change this if needed)




References:

Get back your Intune PowerShell Scripts – Modern IT – Cloud – Workplace (oliverkieselbach.com) 


Intune/Get-DeviceManagementScripts.ps1 at master · okieselbach/Intune · GitHub 


Add PowerShell scripts to Windows 10/11 devices in Microsoft Intune | Microsoft Docs 


Microsoft Intune PowerShell Module | Tech Wizard