首页 > 解决方案 > SSIS 包中的 Powershell RunAs 管理员

问题描述

我正在尝试远程连接到服务器并运行 powershell 脚本以在 SSIS 执行进程任务中打开 Windows 防火墙中的端口在此处输入图像描述

这是 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 帮助主题。+ CategoryInfo : OpenError: (SERVERNAME:String) [], PSRemotingTransportException + FullyQualifiederrorId : AccessDenied, PSSessionStateBroken

我试图在本地运行 PS 脚本及其工作,运行 ssis 的帐户是目标服务器上的本地管理员。是否可以在 SSIS 包中以管理员身份运行?

谢谢哈坎

标签: powershellssispowershell-remoting

解决方案


推荐阅读