1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Invoke-Sqlcmd コマンドで WID に接続する

Posted at

WSUS などでおなじみの Windows Internal Database へアクセスするときに、下記のようなコマンドを実行します。

Invoke-Sqlcmd -ServerInstance "\\.\pipe\microsoft##WID\tsql\query" -Query "Select @@version"

が、下記のようなエラーが発生するようになってしまいました。
Invoke-Sqlcmd : The instance of SQL Server you attempted to connect to does not support encryption.

Invoke-Sqlcmd : The instance of SQL Server you attempted to connect to does not support encryption.
発生場所 行:1 文字:1
+ Invoke-Sqlcmd -ServerInstance "\\.\pipe\microsoft##WID\tsql\query" -Q ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd]、SqlException
    + FullyQualifiedErrorId : SqlExceptionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

Invoke-Sqlcmd : '' の解析中に無効な構文が見つかりました。
発生場所 行:1 文字:1
+ Invoke-Sqlcmd -ServerInstance "\\.\pipe\microsoft##WID\tsql\query" -Q ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ParserError: (:) [Invoke-Sqlcmd], BatchParserException
    + FullyQualifiedErrorId : ExecutionFailureException,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

エラーを読むと、暗号化をサポートしていないことが原因のようです。
暗号化が既定で必要になったことが要因と思われます。
https://learn.microsoft.com/ja-jp/sql/connect/oledb/major-version-differences?view=sql-server-ver16

-Encrypt Optional を追加することにより解決するようです。

Invoke-Sqlcmd -ServerInstance "\\.\pipe\microsoft##WID\tsql\query" -Query "Select @@version" -Encrypt Optional

Microsoft SQL Server 2014 (SP2-GDR) (KB4057120) - 12.0.5214.6 (X64) Jan  9 2018 15:03:12 Copyright (c) Microsoft Corporation Windows Internal Database (64-bit) on Windows NT 6.3 <X64> (Build 20348: )

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?