Download your Intune powershell scripts

You probably already faced the issue. Your customer has a nice powershell script on his endpoint manager admin center but he can’t provide you the last version of the script. He may have lost the main file, no coding repositories, etc. Guess what, you can’t download it directly from Azure portal! But there is always a way to get what we need if there is no GUI on Azure. Let’s do some powershell!

With this method, you will be able to download the working scripts directly from Azure

On a powershell administrator window, launch the following code :

#Get Graph API Intune Module
Install-Module NuGet
Install-Module -Name Microsoft.Graph.Intune
Import-Module Microsoft.Graph.Intune -Global

#The path where the scripts will be saved
$Path = "C:\temp" 

#The connection to Azure Graph
Connect-MSGraph  

#Get Graph scripts
$ScriptsData = Invoke-MSGraphRequest -Url "https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts" -HttpMethod GET

$ScriptsInfos = $ScriptsData.value | select id,fileName,displayname
$NBScripts = ($ScriptsInfos).count

if ($NBScripts -gt 0){
    Write-Host "Found $NBScripts scripts :" -ForegroundColor Yellow
    $ScriptsInfos | FT DisplayName,filename
    Write-Host "Downloading Scripts..." -ForegroundColor Yellow
    foreach($ScriptInfo in $ScriptsInfos){
        #Get the script
        $script = Invoke-MSGraphRequest -Url "https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts/$($scriptInfo.id)" -HttpMethod GET
        #Save the script
        [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($($script.scriptContent))) | Out-File -FilePath $(Join-Path $Path $($script.fileName))  -Encoding ASCII 
    }
    Write-Host "All scripts downloaded!" -ForegroundColor Yellow        
}
Example output

Information Technology addict since Windows 3.11, I specialised myself on Cloud technologies. I did not forget my development skills in Scripting (Powershell) and Web (PHP,CSS,HTML,Javascript). I love sharing my knowledge and help companies in their cloud journey. Feel free to contact me.

Leave a Reply

Your email address will not be published. Required fields are marked *

fifteen + two =

*