Skip to content

ConvertTo-Hashtable

SYNOPSIS

Converts an object to a hashtable.

SYNTAX

ConvertTo-Hashtable [-InputObject] <PSObject> [-ProgressAction <ActionPreference>] [<CommonParameters>]

DESCRIPTION

Recursively converts an object to a hashtable. This function is useful for converting complex objects to hashtables for serialization or other purposes.

EXAMPLES

EXAMPLE 1

$object = [PSCustomObject]@{
    Name        = 'John Doe'
    Age         = 30
    Address     = [PSCustomObject]@{
        Street  = '123 Main St'
        City    = 'Somewhere'
        ZipCode = '12345'
    }
    Occupations = @(
        [PSCustomObject]@{
            Title   = 'Developer'
            Company = 'TechCorp'
        },
        [PSCustomObject]@{
            Title   = 'Consultant'
            Company = 'ConsultCorp'
        }
    )
}
$hashtable = ConvertTo-Hashtable -InputObject $object

This will return a hashtable representation of the object.

PARAMETERS

-InputObject

The object to convert to a hashtable.

Type: PSObject
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
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.

INPUTS

OUTPUTS

NOTES