ConvertTo-Hashtable.ps1 702 B

123456789101112131415161718192021222324252627282930313233
  1. param (
  2. [Parameter(ValueFromPipeline)]
  3. $InputObject
  4. )
  5. process
  6. {
  7. if ($null -eq $InputObject) { return $null }
  8. if ($InputObject -is [System.Collections.IEnumerable] -and $InputObject -isnot [string])
  9. {
  10. $collection = @(
  11. foreach ($object in $InputObject) { &$PSCommandPath $object }
  12. )
  13. Write-Output -NoEnumerate $collection
  14. }
  15. elseif ($InputObject -is [psobject])
  16. {
  17. $hash = @{}
  18. foreach ($property in $InputObject.PSObject.Properties)
  19. {
  20. $hash[$property.Name] = (&$PSCommandPath $property.Value).PSObject.BaseObject
  21. }
  22. $hash
  23. }
  24. else
  25. {
  26. $InputObject
  27. }
  28. }