iNNOKENTIY21
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
Код: using assembly System.ServiceProcess using namespace System.ServiceProcess enum Фрукты { Яблоко Апельсин Банан Персик } class отбалды { [ServiceStartMode]$a = [ServiceStartMode]::Automatic [Фрукты]$b } [отбалды[]]$белиберда = @( @{a = [ServiceStartMode]::Automatic; b = [Фрукты]::Яблоко}, @{a = [ServiceStartMode]::Manual; b = [Фрукты]::Апельсин} ) Filter ConvertTo-EnumsAsStrings ([int] $Depth = 2, [int] $CurrDepth = 0) { if ($_ -is [enum]) { # enum value -> convert to symbolic name as string $_.ToString() } elseif ($null -eq $_ -or $_.GetType().IsPrimitive -or $_ -is [string] -or $_ -is [decimal] -or $_ -is [datetime] -or $_ -is [datetimeoffset]) { $_ } elseif ($_ -is [Collections.IEnumerable]) { , ($_ | ConvertTo-EnumsAsStrings -Depth $Depth -CurrDepth ($CurrDepth+1)) } else { # non-primitive type -> recurse on properties if ($CurrDepth -gt $Depth) { # depth exceeded -> return .ToString() representation "$_" } else { $oht = [ordered] @{} foreach ($prop in $_.psobject.properties) { if ($prop.Value -is [Collections.IEnumerable] -and -not $prop.Value -is [string]) { $oht[$prop.Name] = @($prop.Value | ConvertTo-EnumsAsStrings -Depth $Depth -CurrDepth ($CurrDepth+1)) } else { $oht[$prop.Name] = $prop.Value | ConvertTo-EnumsAsStrings -Depth $Depth -CurrDepth ($CurrDepth+1) } } $oht } } } Clear-Host $белиберда "`n`n`tковертируем в json:`n`n" $белиберда | ConvertTo-EnumsAsStrings | ConvertTo-Json |
|