LanguagePrimitives.ConvertTo Method (Object, Type)

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Converts an object from one type to another.

Namespace:   System.Management.Automation
Assembly:  System.Management.Automation (in System.Management.Automation.dll)

public static object ConvertTo(
	object valueToConvert,
	Type resultType
)

Parameters

valueToConvert
Type: System.Object

The object to convert.

resultType
Type: System.Type

The type of object to convert to.

Return Value

Type: System.Object

The converted object.

Exception Condition
ArgumentNullException

resultType is null.

PSInvalidCastException

Windows PowerShell cannot convert the object.

-or-

A custom converter threw an exception.

Windows PowerShell can use standard Windows PowerShell language converters or custom converters to perform the type conversion. For more information about these converters, possible return values, and exceptions that might be thrown during the conversion process, see ETS Type Conversion [ps].

Return to top

Community Additions

ADD
Show: