我有以下连接字符串
{"Authentication Kind":"UsernamePassword","Username":"someID1","Password":"Yu#gh456!ts","EncryptConnection":true}
我正在尝试使用*******显示密码,因此我需要将其转换为SqlConnectionStringBuilder
类型,因为它很容易替换为该属性。我对非json结构的字符串很好用
[System.Data.SqlClient.SqlConnectionStringBuilder]::New('{"Authentication Kind":"UsernamePassword","Username":"someID1","Password":"Yu#gh456!ts","EncryptConnection":true}')
我遇到此错误:
无法将值转换为类型 System.Data.SqlClient.SqlConnectionStringBuilder
如何将其转换为SqlConnectionStringBuilder
类型可以接受的连接字符串?
答案 0 :(得分:2)
您可以先将其转换为PSObject。
$Json = '{"Authentication Kind":"UsernamePassword","Username":"someID1","Password":"Yu#gh456!ts","EncryptConnection":true}'
$Sql = $Json | ConvertFrom-Json
$Sql.Password
您可以从那里使用属性创建一个新字符串,或将其转换回JSON。