Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 调用命令脚本块不生成输出_Shell_Powershell_Citrix - Fatal编程技术网

Shell 调用命令脚本块不生成输出

Shell 调用命令脚本块不生成输出,shell,powershell,citrix,Shell,Powershell,Citrix,我正在尝试在远程powershell会话中使用脚本块。此命令正在运行,我得到了关于机器状态的输出: $SecurePassword = $ParamPassword | ConvertTo-SecureString -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ` -ArgumentList $UserName, $SecurePassword $ParamDomain =

我正在尝试在远程powershell会话中使用脚本块。此命令正在运行,我得到了关于机器状态的输出:

$SecurePassword = $ParamPassword | ConvertTo-SecureString -AsPlainText -Force  
$cred = New-Object System.Management.Automation.PSCredential `
 -ArgumentList $UserName, $SecurePassword
$ParamDomain = 'mydomain'
$ParamHostname = "myhostname"

$fullhost =  "$ParamDomain"+"\"+"$ParamHostname"  

#Get-BrokerMachine No1
if ($ParamCommand -eq 'Get-BrokerMachine'){
$s = New-PSSession -computerName $desktopbroker -credential $cred
Invoke-Command -Session $s -ScriptBlock { param( $fullhost ) ;asnp citrix.* ; Get-BrokerMachine -machinename $fullhost  } -Args $fullhost
}
我的第二次迭代也使用了scriptblock,但失败了。未执行命令
Get BrokerMachine
,并且没有输出

#Get-BrokerMachine No2
if ($ParamCommand -eq 'Get-BrokerMachine'){
$ScriptBlock = {
    asnp citrix.* ; Get-BrokerMachine -machinename $fullhost 
};
$s = New-PSSession -computerName $desktopbroker -credential $cred
Invoke-Command -Session $s -ScriptBlock $ScriptBlock 

}

有人能解释一下第二个脚本的错误吗?

第二个脚本中缺少的一件重要事情是,您没有将
$fullhost
作为参数传递。在远程系统上调用scriptblock时,
$fullhost
将是
$null

粗略猜测,您需要做如下操作:

#Get-BrokerMachine No2
if ($ParamCommand -eq 'Get-BrokerMachine'){
    $ScriptBlock = {
        param($host)
        asnp citrix.* ; Get-BrokerMachine -machinename $host 
    };
    $s = New-PSSession -computerName $desktopbroker -credential $cred
    Invoke-Command -Session $s -ScriptBlock $ScriptBlock -ArgumentList $fullhost
}

我将scriptblock中变量的名称更改为
$host
,以消除作用域的潜在模糊性。

$fullhost
很可能是$null,因为它没有传递给命令。我打赌,您需要将
$fullhost
作为参数传递。您在第一个示例中就是这样做的。不是你的第二个