In PowerShell, how do you access DAO enumeration constants, such as RecordsetTypeEnum dbOpenTable (1) or DataTypeEnum adVarNumeric (139)? Right now, I'm simply putting them in as magic numbers, but it would be much cleaner and easier to read to refer to the proper constants.
CodePudding user response:
You could define a custom enum type with the names needed:
enum DAODataType {
adBigInt = 0x14
adBinary = 0x80
adBoolean = 0x0B
adBSTR = 0x08
adChapter = 0x88
adChar = 0x81
adCurrency = 0x06
adDate = 0x07
adDBDate = 0x85
adDBTime = 0x86
adDBTimeStamp = 0x87
adDecimal = 0x0E
adDouble = 0x05
adEmpty = 0x00
adError = 0x0A
adFileTime = 0x40
adGUID = 0x48
adIDispatch = 0x09
adInteger = 0x03
adIUnknown = 0x0D
adLongVarBinary = 0xCD
adLongVarChar = 0xC9
adLongVarWChar = 0xCB
adNumeric = 0x83
adPropVariant = 0x8A
adSingle = 0x04
adSmallInt = 0x02
adTinyInt = 0x10
adUnsignedBigInt = 0x15
adUnsignedInt = 0x13
adUnsignedSmallInt = 0x12
adUnsignedTinyInt = 0x11
adUserDefined = 0x84
adVarBinary = 0xCC
adVarChar = 0xC8
adVariant = 0x0C
adVarNumeric = 0x8B
adVarWChar = 0xCA
adWChar = 0x82
}
Then pass [DAODataType]::adVarNumeric instead of 139
CodePudding user response:
For RecordsetTypeEnum dbOpenTable (which comes from Access), you can use:
[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Access.Dao") | Out-null
[int][Microsoft.Office.Interop.Access.Dao.RecordsetTypeEnum]::dbOpenTable
For DataTypeEnum adVarNumeric (which comes from ADODB, not Access) you can use:
[Reflection.Assembly]::LoadWithPartialName("ADODB") | Out-null
[int][ADODB.DataTypeEnum]::adVarNumeric
