使用 ConvertTo-Json 转换为 JSON 时保留数据类型名称 [英] Preserve datatype name when converting to JSON with ConvertTo-Json

查看:22
本文介绍了使用 ConvertTo-Json 转换为 JSON 时保留数据类型名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的 SSIS 目录环境导出到 JSON 文件(使用 PowerShell).当我选择正确的列时,我看到String"和Int16"作为类型的值:但是当我使用 有什么建议吗?

I'm trying to export my SSIS catalog environment to a JSON file (with PowerShell). When I select the right columns I see "String" and "Int16" as value for the Type: but when I convert to JSON with ConvertTo-Json it shows the int values instead of the string values: Any suggestions?

推荐答案

看起来 Type 值属于 [System.Data.DbType] 类型.ConvertTo-Json 将值名称转换为 DbType 枚举的基础数值.

Looks like the Type values are of type [System.Data.DbType]. ConvertTo-Json converts the value names to the underlying numerical value of the DbType enum.

您可以使用 Select-Object 语句覆盖此行为:

You can override this behavior with the Select-Object statement:

$Environment.Variables |Select-Object Name,Description,@{Name='Type';Expression={"$($_.Type)"}},Sensitivity,Value |ConvertTo-Json

这篇关于使用 ConvertTo-Json 转换为 JSON 时保留数据类型名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆