Целые числа (в диапазоне от -2 ^ 32 до 2 ^ 32), которые не приведены или не заключены в кавычки, приводятся к типу значения Int32
. Это происходит при создании записи таблицы ha sh @{0='something'}
, где 0
равно Int32
. Поскольку значение, предоставленное свойством LicenseStatus
, равно Uint32
, типы ключей не совпадают. Вы должны форсировать проблему либо приведением в таблицу ha sh, либо в вычисляемое свойство.
# Casting in calculated property
$statusLookup=@{0='Unlicensed'; 1='Licensed'; 2='OOBGrace'; 3='OOTGrace'; 4='NonGenuineGrace'; 5='Notification'; 6='ExtendedGrace'}
Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" | where { $_.PartialProductKey } |
select Description, LicenseStatus, @{N='LicenseStatusText';E={$statusLookup[[int]$_.LicenseStatus]}}
# Casting in hash table
$statusLookup=@{[uint32]0='Unlicensed'; [uint32]1='Licensed'; [uint32]2='OOBGrace'; [uint32]3='OOTGrace'; [uint32]4='NonGenuineGrace'; [uint32]5='Notification'; [uint32]6='ExtendedGrace'}
Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" | where { $_.PartialProductKey } |
select Description, LicenseStatus, @{N='LicenseStatusText';E={$statusLookup[$_.LicenseStatus]}}