当通过调用命令调用时,我观察到 IIS7 CLI 实用程序 appcmd 的这种奇怪行为。
这是我正在尝试执行的一小段命令。
PS C:\>appcmd list config /section:applicationPools | Select-String -SimpleMatch "SomeAppPool" -context 0,4 | Out-String -Stream | Select-String " pingingEnabled=""true"""
该命令执行得非常好[在设置了所有 %PATH% 变量的 IIS7 机器上完成]。我得到一个像
<processModel pingingEnabled="true" />
通过远程机器的调用命令完成同样的事情。
远程版本-I
PS C:\>invoke-command -computername iismachine -credential $creds -scriptblock {
appcmd list config /section:applicationPools | Select-String -SimpleMatch "SomeAppPool" -context 0,4 | Out-String -Stream | Select-String " pingingEnabled=""true"""
}
没有输出,只有三个空行!!!
虽然如果我通过创建一个远程 powershell 会话来做到这一点,它开始工作正常..
远程版本-II
PS C:\>enter-pssession -computername iismachine -credential $creds;
[iismachine]: PS C:\Users\onewildgamer\Documents>invoke-command -scriptblock {
appcmd list config /section:applicationPools | Select-String -SimpleMatch "SomeAppPool" -context 0,4 | Out-String -Stream | Select-String " pingingEnabled=""true"""
}
现在行为有所不同,我不怀疑用户权限问题。
如果我做错了什么,请告诉我。我一生都无法弄清楚为什么这不起作用。