例如,我想像从 vb 一样使用 SQLConnection 对象。我想这样做:
例如
$conn = New-Object system.data.sqlclient.sqlconnectionstringbuilder
$conn.DataSource = 'myserver'
Run Code Online (Sandbox Code Playgroud)
但这失败了:
Keyword not supported: 'DataSource'.
At line:1 char:4
+ $conn. <<<< DataSource = 'myserver'
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
Run Code Online (Sandbox Code Playgroud)
虽然:
PS C:\WINDOWS\system32\WindowsPowerShell> $conn|Get-Member *sour*
TypeName: System.Data.SqlClient.SqlConnectionStringBuilder
Name MemberType Definition
---- ---------- ----------
DataSource Property System.String DataSource {get;set;}
Run Code Online (Sandbox Code Playgroud)
我的 Powershell 版本:
PS C:\WINDOWS\system32\WindowsPowerShell> $PSVersionTable
Name Value
---- -----
CLRVersion 2.0.50727.3634
BuildVersion 6.0.6002.18111
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion …Run Code Online (Sandbox Code Playgroud) powershell ×1