# properties to exclude (add or remove as needed) $blacklist = 'FileList', 'Tags'
$data = Invoke-RestMethod-Uri$url-UseBasicParsing | ForEach-Object { $hash = [Ordered]@{} $moduleInfo = $_.Properties foreach($_in$moduleInfo.PSObject.Properties) { # name of property $name = $_.Name # if it is in blacklist, skip and continue with next property if ($name-in$blacklist) { continue } # if it is the property "name", then skip # all remaining (xml default properties) if ($name-eq'Name') { break }
# if type is "xmlelement", retrieve underlying text value in #text if ($_.TypeNameOfValue -eq'System.Xml.XmlElement') { $hash[$name] = $moduleInfo.$name.'#text'
# if a datatype is assigned, try and convert to appropriate type if ($moduleInfo.$name.type -like'Edm.*') { $typename = $moduleInfo.$name.type.replace('Edm.','') $hash[$name] = $hash[$name] -as$typename } } else { $hash[$name] = $_.Value } }
# convert a hash table to object and return it [PSCustomObject]$hash }