SetPropertyValue在不承认PowerShell中

问题描述:

我的操作系统是Windows 10,我使用PowerShell来尝试创建一个DSN条目 这是我用过的命令:SetPropertyValue在不承认PowerShell中

Add-OdbcDsn -Name MyTest2 -DriverName "SQL Server Native Client 11.0" -DsnType System 
    -SetPropertyValue @("Server=MyServer", "Description=My second Test","User=MyTestUser","Password=12345", "Database=MyTestDB") 

DSN的条目被创建,但我得到这个错误:

-SetPropertyValue : The term '-SetPropertyValue' is not recognized as the name of a cmdlet, function, script file, or 
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 
At line:2 char:5 
+  -SetPropertyValue @("Server=MyServer", "Description=My se ... 
+  ~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : ObjectNotFound: (-SetPropertyValue:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

请告知我的声明中出现了什么问题,如果可能的话如何解决?

更新:

我加入了2线

Add-OdbcDsn -Name MyTest3 -DriverName "SQL Server Native Client 11.0" -DsnType System -Platform '32-bit' -SetPropertyValue @("Server=MyServer", "Description=My second Test","User=MyTestUser","Password=12345", "Database=TestDB") 

,我得到这个错误:

Add-OdbcDsn : Invalid keyword-value pairs (Installer error code: 8). 
At line:1 char:1 
+ Add-OdbcDsn -Name MyTest3 -DriverName "SQL Server Native Client 11.0" ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (MyTest2 (32-bit ODBC System DSN):Root/Microsoft/...SFT_OdbcDsnTask) [Add-OdbcD 
    sn], CimException 
    + FullyQualifiedErrorId : MI RESULT 0,Add-OdbcDsn 

Add-OdbcDsn : Driver's ConfigDSN, ConfigDriver, or ConfigTranslator failed (Installer error code: 11). 
At line:1 char:1 
+ Add-OdbcDsn -Name MyTest3 -DriverName "SQL Serv 
+2

参数不会自动连接到上一行,因此您需要'在上一行的末尾。 [如何输入多行命令?](// stackoverflow.com/q/3235850) – wOxxOm

+0

我明白了......谢谢!我在一行中加入了它们,但是我仍然遇到了错误...请参阅我的更新 – user1205746

+0

我刚刚更新了一行中的所有内容 – user1205746

你更新后的问题是关键的用户名和密码不被识别为一个SQL连接字符串。

将它们更新到"Uid=MyTestUser","Pwd=12345"它应该工作。

更多信息可在connectionstrings.com找到。

+0

你能为我澄清一下吗?你是说我需要分两步来做:首先创建没有uid和pwd的条目,然后用uid和pwd再次使用set_odbcdsn和-SetPropertyValue更新新添加的条目? – user1205746

+0

这是我得到的错误:尝试设置DSN的{UID或PWD}键。这些密钥不应该存储在注册表中以保证安全 的原因。我无法设置uid和pwd。不知道你是如何做到的。请指教。 – user1205746