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

Here is the Powershell code:

$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

Here is the error i got:

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

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

谢谢Håkan