Private/Get-PlistData.ps1
|
function Get-PlistData { <# .SYNOPSIS Reads an entire plist file as a PowerShell object using plutil. .DESCRIPTION Uses /usr/bin/plutil to convert the plist to JSON in a single process spawn and returns a PSObject. Significantly faster than multiple PlistBuddy calls for the same file (1 process instead of N). #> param([string]$PlistPath) if ([string]::IsNullOrWhiteSpace($PlistPath) -or -not (Test-Path -LiteralPath $PlistPath)) { return $null } $json = /usr/bin/plutil -convert json -o - "$PlistPath" 2>$null if ([string]::IsNullOrWhiteSpace($json)) { return $null } try { return $json | ConvertFrom-Json -ErrorAction Stop } catch { return $null } } |