Skip to content

Commit 0d99f19

Browse files
committed
Fix for issue #109
DeviceConfiguration_Export.ps1 also exports "Software update" policies #109
1 parent 278a5e6 commit 0d99f19

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

DeviceConfiguration/DeviceConfiguration_Export.ps1

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -219,51 +219,38 @@ $ExportPath
219219

220220
if($JSON -eq "" -or $JSON -eq $null){
221221

222-
write-host "No JSON specified, please specify valid JSON..." -f Red
222+
write-host "No JSON specified, please specify valid JSON..." -f Red
223223

224224
}
225225

226226
elseif(!$ExportPath){
227227

228-
write-host "No export path parameter set, please provide a path to export the file" -f Red
228+
write-host "No export path parameter set, please provide a path to export the file" -f Red
229229

230230
}
231231

232232
elseif(!(Test-Path $ExportPath)){
233233

234-
write-host "$ExportPath doesn't exist, can't export JSON Data" -f Red
234+
write-host "$ExportPath doesn't exist, can't export JSON Data" -f Red
235235

236236
}
237237

238238
else {
239239

240-
$JSON1 = ConvertTo-Json $JSON -Depth 5
240+
$JSON1 = ConvertTo-Json $JSON -Depth 5
241241

242-
$JSON_Convert = $JSON1 | ConvertFrom-Json
242+
$JSON_Convert = $JSON1 | ConvertFrom-Json
243243

244-
$displayName = $JSON_Convert.displayName
244+
$displayName = $JSON_Convert.displayName
245245

246-
# Updating display name to follow file naming conventions - https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
247-
$DisplayName = $DisplayName -replace '\<|\>|:|"|/|\\|\||\?|\*', "_"
246+
# Updating display name to follow file naming conventions - https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
247+
$DisplayName = $DisplayName -replace '\<|\>|:|"|/|\\|\||\?|\*', "_"
248248

249-
$Properties = ($JSON_Convert | Get-Member | ? { $_.MemberType -eq "NoteProperty" }).Name
250-
251-
$FileName_CSV = "$DisplayName" + "_" + $(get-date -f dd-MM-yyyy-H-mm-ss) + ".csv"
252249
$FileName_JSON = "$DisplayName" + "_" + $(get-date -f dd-MM-yyyy-H-mm-ss) + ".json"
253250

254-
$Object = New-Object System.Object
255-
256-
foreach($Property in $Properties){
257-
258-
$Object | Add-Member -MemberType NoteProperty -Name $Property -Value $JSON_Convert.$Property
259-
260-
}
261-
262251
write-host "Export Path:" "$ExportPath"
263252

264-
$Object | Export-Csv -LiteralPath "$ExportPath\$FileName_CSV" -Delimiter "," -NoTypeInformation -Append
265253
$JSON1 | Set-Content -LiteralPath "$ExportPath\$FileName_JSON"
266-
write-host "CSV created in $ExportPath\$FileName_CSV..." -f cyan
267254
write-host "JSON created in $ExportPath\$FileName_JSON..." -f cyan
268255

269256
}
@@ -365,8 +352,8 @@ $ExportPath = Read-Host -Prompt "Please specify a path to export the policy data
365352

366353
Write-Host
367354

368-
$DCPs = Get-DeviceConfigurationPolicy
369-
355+
# Filtering out iOS and Windows Software Update Policies
356+
$DCPs = Get-DeviceConfigurationPolicy | Where-Object { ($_.'@odata.type' -ne "#microsoft.graph.iosUpdateConfiguration") -and ($_.'@odata.type' -ne "#microsoft.graph.windowsUpdateForBusinessConfiguration") }
370357
foreach($DCP in $DCPs){
371358

372359
write-host "Device Configuration Policy:"$DCP.displayName -f Yellow

0 commit comments

Comments
 (0)