使用PowerShell远程连接到SQL Integration Services时访问被拒绝

时间:2017-08-23 14:12:10

标签: sql-server powershell

我有以下PowerShell脚本连接到远程Sql Server集成服务:

param (
    [string]$Server = "GFDBS0002",
    [string]$Instance = "DEFAULT",
    [string]$Folder = "<SSIS folder>",
    [string]$Project
)

Import-Module sqlps -DisableNameChecking

$p = Get-Item SQLSERVER:\SSIS\$Server\$Instance\Catalogs\SSISDB\Folders\$Folder\Projects\$Project

执行脚本失败:

  

“警告:无法获取SQL Server服务信息。尝试   连接到'GFDBS0002'上的WMI失败,出现以下错误:   拒绝访问。 (Undtagelse fra HRESULT:0x80070005(E_ACCESSDENIED))“

I can successfully connect to the server with Windows Management Instrumentation Tester with my AD-user

enter image description here

关于我可以做什么来连接的任何建议?

解决方案

根据@ArcSet的回答,以下解决方案有效:

$secpasswd = ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("username", $secpasswd)

$p = Get-Item SQLSERVER:\SSIS\$Server\$Instance\Catalogs\SSISDB\Folders\$Folder\Projects\$Project -Credential $mycreds

1 个答案:

答案 0 :(得分:1)

WMI连接未通过您的身份,需要您使用您的凭据登录。

var s = "00001111";
var n = 0d;

for(var i = 0; i < s.Length; i++)
{   
    var d = s[s.Length - 1 - i] == '0' ? 0 : 1;     
    n += (d * Math.Pow(2, i));
}

var b = (byte)(((int)n) & 0xFF);