ConvertTo-Hashtable
July 25, 2026 ยท View on GitHub
SYNOPSIS
Convert an object into a hashtable.
SYNTAX
ConvertTo-Hashtable [-InputObject] <Object> [-NoEmpty] [-Exclude <String[]>]
[-Alphabetical] [<CommonParameters>]
DESCRIPTION
This command will take an object and create a hashtable based on its properties. You can have the hashtable exclude some properties as well as properties that have no value.
EXAMPLES
Example 1
PS C:\> Get-Process -id $pid | Select-Object name,id,handles,WorkingSet | ConvertTo-Hashtable
Name Value
---- -----
WorkingSet 418377728
Name powershell_ise
Id 3456
Handles 958
Example 2
PS C:\> $hash = Get-Service spooler |
ConvertTo-Hashtable -Exclude CanStop,CanPauseAndContinue -NoEmpty
PS C:\> $hash
Name Value
---- -----
ServiceType Win32OwnProcess, InteractiveProcess
ServiceName spooler
ServiceHandle SafeServiceHandle
DependentServices {Fax}
ServicesDependedOn {RPCSS, http}
Name spooler
Status Running
MachineName .
RequiredServices {RPCSS, http}
DisplayName Print Spooler
This created a hashtable from the Spooler service object, skipping empty properties and excluding CanStop and CanPauseAndContinue.
Example 3
PS C:\> Get-Service bits |
Select-Object Name,DisplayName,Status,
@{Name="Computername";Expression={$_.MachineName}} |
ConvertTo-Hashtable -Alphabetical
Name Value
---- -----
Computername .
DisplayName Background Intelligent Transfer Service
Name bits
Status Running
Convert an object to a hashtable and order the properties alphabetically.
PARAMETERS
-InputObject
A PowerShell object to convert to a hashtable.
Type: Object
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
-NoEmpty
Do not include object properties that have no value.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-Exclude
An array of property names to exclude from the hashtable.
Type: String[]
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Alphabetical
Create a hashtable with property names arranged alphabetically.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
System.Object
OUTPUTS
System.Collections.Specialized.OrderedDictionary
NOTES
Learn more about PowerShell: https://jdhitsolutions.com/yourls/newsletter