Skip to content

ConvertTo HashTable

dscbot edited this page Feb 13, 2024 · 2 revisions

ConvertTo-HashTable

SYNOPSIS

Converts CimInstances into a hashtable.

SYNTAX

ConvertTo-HashTable -CimInstance <CimInstance[]> [<CommonParameters>]

DESCRIPTION

This function is used to convert a CimInstance array containing MSFT_KeyValuePair objects into a hashtable.

EXAMPLES

EXAMPLE 1

$newInstanceParameters = @{
    ClassName = 'MSFT_KeyValuePair'
    Namespace = 'root/microsoft/Windows/DesiredStateConfiguration'
    ClientOnly = $true
}
$cimInstance = [Microsoft.Management.Infrastructure.CimInstance[]] (
    (New-CimInstance @newInstanceParameters -Property @{
        Key   = 'FirstName'
        Value = 'John'
    }),
    (New-CimInstance @newInstanceParameters -Property @{
        Key   = 'LastName'
        Value = 'Smith'
    })
)
ConvertTo-HashTable -CimInstance $cimInstance

This creates a array of CimInstances using the class name MSFT_KeyValuePair and passes it to ConvertTo-HashTable which returns a hashtable.

PARAMETERS

-CimInstance

An array of CimInstances or a single CimInstance object to convert.

Type: CimInstance[]
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
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

System.Collections.Hashtable

NOTES

RELATED LINKS

Clone this wiki locally