Powershell RunAs管理员在SSIS包中

时间:2018-05-09 05:59:25

标签: powershell ssis powershell-remoting

尝试远程连接到服务器并运行powershell脚本以在SSIS执行流程任务中打开Windows防火墙中的端口enter image description here

以下是Powershell代码:

$computername = hostname

$script = {
$FireWallRule_1 = Get-NetFirewallRule
    $par1 = @{
    DisplayName = "DAC"
    LocalPort = 1434
    Direction="Inbound"
    Protocol ="TCP" 
    Action = "Allow"
}
$FireWallRule_2 = Get-NetFirewallRule
    $par2 = @{
    DisplayName = "MSSQLSERVER"
    LocalPort = 1433
    Direction="Inbound"
    Protocol ="TCP" 
    Action = "Allow"
}

$par1.Localport = 1434
$par1.DisplayName = "DAC"
if (-not $FireWallRule_1.DisplayName.Contains($par1.DisplayName)) {New-NetFirewallRule @par1}

$par2.LocalPort = 1433
$par2.DisplayName = "MSSQLSERVER"
if (-not $FireWallRule_2.DisplayName.Contains($par2.DisplayName)) {New-NetFirewallRule @par2}

}

Invoke-Command -ScriptBlock $script -ComputerName $computername

这是我得到的错误:

  

连接到远程服务器[SERVERNAME]失败,并显示以下错误消息:拒绝访问。有关更多信息,请参阅   aboute_Remote_Troubleshooting Helptopic。   + CategoryInfo:OpenError:(SERVERNAME:String)[],PSRemotingTransportException   + FullyQualifiederrorId:AccessDenied,PSSessionStateBroken

我试图在本地运行PS脚本并且它正常工作,运行ssis的帐户是目标服务器上的本地管理员。是否可以在SSIS包中使用RunAs Administrator?

感谢Håkan

0 个答案:

没有答案