{"id":406,"date":"2022-05-09T09:58:02","date_gmt":"2022-05-09T09:58:02","guid":{"rendered":"https:\/\/tomtechproductions.be\/?p=406"},"modified":"2022-05-09T09:58:02","modified_gmt":"2022-05-09T09:58:02","slug":"export-powershell-scripts-from-intune","status":"publish","type":"post","link":"https:\/\/blog.tomtechproductions.be\/index.php\/2022\/05\/09\/export-powershell-scripts-from-intune\/","title":{"rendered":"Export powershell scripts from intune"},"content":{"rendered":"\n<p>Source: <a href=\"https:\/\/github.com\/okieselbach\/Intune\/blob\/master\/Get-DeviceManagementScripts.ps1\">Intune\/Get-DeviceManagementScripts.ps1 at master \u00b7 okieselbach\/Intune \u00b7 GitHub<\/a><br>Source: <a href=\"https:\/\/oliverkieselbach.com\/2020\/02\/06\/get-back-your-intune-powershell-scripts\/\">Get back your Intune PowerShell Scripts \u2013 Modern IT \u2013 Cloud \u2013 Workplace (oliverkieselbach.com)<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Import-Module Microsoft.Graph.Intune\nConnect-MSGraph\n\n####################################################\n\n#region Initialization code\n\n$m = Get-Module -Name Microsoft.Graph.Intune -ListAvailable\nif (-not $m)\n{\n    Install-Module NuGet -Force\n    Install-Module Microsoft.Graph.Intune\n}\nImport-Module Microsoft.Graph.Intune -Global\n\n#endregion\n\n####################################################\n\nFunction Get-DeviceManagementScripts(){\n&lt;#\n.SYNOPSIS\nGet all or individual Intune PowerShell scripts and save them in specified folder.\n \n.DESCRIPTION\nThe Get-DeviceManagementScripts cmdlet downloads all or individual PowerShell scripts from Intune to a specified folder.\nInitial Author: Oliver Kieselbach (oliverkieselbach.com)\nThe script is provided \"AS IS\" with no warranties.\n \n.PARAMETER FolderPath\nThe folder where the script(s) are saved.\n.PARAMETER FileName\nAn optional parameter to specify an explicit PowerShell script to download.\n.EXAMPLE\nDownload all Intune PowerShell scripts to the specified folder\nGet-DeviceManagementScripts -FolderPath C:\\temp \n.EXAMPLE\nDownload an individual PowerShell script to the specified folder\nGet-DeviceManagementScripts -FolderPath C:\\temp -FileName myScript.ps1\n#>\n\n    &#91;CmdletBinding()]\n    Param(\n        &#91;Parameter(Mandatory=$true)]&#91;String] $FolderPath,\n        &#91;Parameter(Mandatory=$false)]&#91;String] $FileName\n    )\n\n    $graphApiVersion = \"Beta\"\n    $graphUrl = \"https:\/\/graph.microsoft.com\/$graphApiVersion\"\n\n    $result = Invoke-MSGraphRequest -Url \"$graphUrl\/deviceManagement\/deviceManagementScripts\" -HttpMethod GET\n\n    if ($FileName){\n        $scriptIds = $result.value | Select-Object id,fileName | Where-Object -Property fileName -eq $FileName\n        $script = Invoke-MSGraphRequest -Url \"$graphUrl\/deviceManagement\/deviceManagementScripts\/$($scriptId.id)\" -HttpMethod GET\n        &#91;System.Text.Encoding]::ASCII.GetString(&#91;System.Convert]::FromBase64String($($script.scriptContent))) | Out-File -Encoding ASCII -FilePath $(Join-Path $FolderPath $($script.fileName))\n    }\n    else{\n        $scriptIds = $result.value | Select-Object id,fileName\n        foreach($scriptId in $scriptIds){\n            $script = Invoke-MSGraphRequest -Url \"$graphUrl\/deviceManagement\/deviceManagementScripts\/$($scriptId.id)\" -HttpMethod GET\n            &#91;System.Text.Encoding]::ASCII.GetString(&#91;System.Convert]::FromBase64String($($script.scriptContent))) | Out-File -Encoding ASCII -FilePath $(Join-Path $FolderPath $($script.fileName))\n        }\n    }\n}\n\nConnect-MSGraph | Out-Null\n\nGet-DeviceManagementScripts -FolderPath C:\\temp<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Source: Intune\/Get-DeviceManagementScripts.ps1 at master \u00b7 okieselbach\/Intune \u00b7 GitHubSource: Get back your Intune PowerShell Scripts \u2013 Modern IT \u2013 Cloud \u2013 Workplace (oliverkieselbach.com)<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-406","post","type-post","status-publish","format-standard","hentry","category-geen-categorie"],"_links":{"self":[{"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/posts\/406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/comments?post=406"}],"version-history":[{"count":0,"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/posts\/406\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/media?parent=406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/categories?post=406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/tags?post=406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}