dimanche 24 mars 2019

Error on type conversion in Powershell EXCEL Com object

The following code:

... $xl = New-Object -ComObject Excel.Application $constants = $xl.gettype().assembly.getexportedtypes() | GM

where-object {$.IsEnum -and $.name -eq 'constants'}

$pso = new-object psobject [enum]::getNames($constants) | foreach { $pso | Add-Member -MemberType NoteProperty $_ ($constants::$_) } $xlConstants = $pso ...

Fails in the [enum]::getNames with the ff. message from Powershell 5.1 ISE: ... Cannot convert argument "enumType", with value: "System.Object[]", for "GetNames" to type "System.Type": "Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Type"." At line:9 char:1 ... Would be grateful for some guidance.

The code was copied from a 2010 answer to a post, which wanted to extract the Excel Enum constants.





Aucun commentaire:

Enregistrer un commentaire