Explorar o código

add convertto-hashtable

Tobias Simetsreiter %!s(int64=2) %!d(string=hai) anos
pai
achega
0a996d42b1
Modificáronse 1 ficheiros con 33 adicións e 0 borrados
  1. 33 0
      bin/ConvertTo-Hashtable.ps1

+ 33 - 0
bin/ConvertTo-Hashtable.ps1

@@ -0,0 +1,33 @@
+param (
+        [Parameter(ValueFromPipeline)]
+        $InputObject
+    )
+
+process
+{
+    if ($null -eq $InputObject) { return $null }
+
+    if ($InputObject -is [System.Collections.IEnumerable] -and $InputObject -isnot [string])
+    {
+        $collection = @(
+            foreach ($object in $InputObject) { &$PSCommandPath $object }
+        )
+
+        Write-Output -NoEnumerate $collection
+    }
+    elseif ($InputObject -is [psobject])
+    {
+        $hash = @{}
+
+        foreach ($property in $InputObject.PSObject.Properties)
+        {
+            $hash[$property.Name] = (&$PSCommandPath $property.Value).PSObject.BaseObject
+        }
+
+        $hash
+    }
+    else
+    {
+        $InputObject
+    }
+}