Powershell 在远程计算机上运行带参数的exe

Powershell 在远程计算机上运行带参数的exe,powershell,powershell-remoting,Powershell,Powershell Remoting,这件事毁了我。我很确定应该是简单的东西不起作用,可能只是一个引号/字符不合适 有一个名为sefautil.exe的lync/Skype工具,它可以完成webGUI所没有的各种奇妙的事情。典型的命令是: C:\Program Files\Skype for Business Server 2015\ResKit>sefautil.exe /server:sfbpool01.domain.local sip:user1@domain.local /setfwddestination:user2

这件事毁了我。我很确定应该是简单的东西不起作用,可能只是一个引号/字符不合适

有一个名为sefautil.exe的lync/Skype工具,它可以完成webGUI所没有的各种奇妙的事情。典型的命令是:

C:\Program Files\Skype for Business Server 2015\ResKit>sefautil.exe /server:sfbpool01.domain.local sip:user1@domain.local /setfwddestination:user2@domain.local /enablefwdimmediate
当远程安装到任何一台机器上时,它都可以正常工作,但我真的很难通过远程PowerShell运行它

无论我通过
invoke command
尝试什么命令,要么给我一个标准的
/?
响应,要么什么都不响应。我已经通过
-ArgumentList
传递了args,作为一个变量,作为我能想到的任何东西,它只是不起作用

是什么让事情变得更加复杂,就像你在没有管理员权限的情况下运行一样,你永远不会得到任何结果。该命令必须作为管理员运行。现在我可以很容易地在我的脚本中加入一个管理模式检查器,但是如果发送命令和发送管理命令一样简单,我就接受它

任何帮助都将不胜感激

@qbanet359

我用了另一种方式,感觉有点便宜,但它确实有效,所以不能抱怨

我在托管sefautil.exe的服务器上创建了一个计划任务,以在提升的权限下运行批处理文件-我称之为sefautil。
我还将sefaUTIL.exe复制到服务器上的C:\TEMP。
然后在我的PowerShell脚本中使用:

$SERVER = "\\computer1\c$\temp"
"cd \" | Out-File "$SERVER\sefautiltest.bat" -Encoding unicode
"cmd /c C:\Temp\sefautil.exe /server:sfbpool01.ad.leics.gov.uk sip:dols.team@leics.gov.uk" | Out-File "$SERVER\sefautiltest.bat" -Append
gc $SERVER\sefautiltest.bat | out-file $server\sefautil.bat -encoding ascii
Invoke-Command -Credential $CREDS -ComputerName computer 01-ScriptBlock { schtasks /Run /TN sefautil }
这几乎可以肯定是一种冗长的方法,但它确实有效

谢谢你给了我一个全新的视角

@qbanet359

我用了另一种方式,感觉有点便宜,但它确实有效,所以不能抱怨

我在托管sefautil.exe的服务器上创建了一个计划任务,以在提升的权限下运行批处理文件-我称之为sefautil。
我还将sefaUTIL.exe复制到服务器上的C:\TEMP。
然后在我的PowerShell脚本中使用:

$SERVER = "\\computer1\c$\temp"
"cd \" | Out-File "$SERVER\sefautiltest.bat" -Encoding unicode
"cmd /c C:\Temp\sefautil.exe /server:sfbpool01.ad.leics.gov.uk sip:dols.team@leics.gov.uk" | Out-File "$SERVER\sefautiltest.bat" -Append
gc $SERVER\sefautiltest.bat | out-file $server\sefautil.bat -encoding ascii
Invoke-Command -Credential $CREDS -ComputerName computer 01-ScriptBlock { schtasks /Run /TN sefautil }
这几乎可以肯定是一种冗长的方法,但它确实有效


谢谢你给了我一个全新的视角

派对有点晚了,但我相信很多其他SfB管理员也会在这里挣扎

我就是这样做的:

Invoke-Command -ComputerName $Global:SefaUtilServer -ScriptBlock {&'C:\Program Files\Skype for Business Server 2015\ResKit\SEFAUtil.exe' '/server:epsachhst-lfe11.epsa.swisscom-mcc.local' $args[0] "/enablefwdnoanswer" "/setfwddestination:$($args[1])" "/callanswerwaittime:$($args[2])"} -Credential $Global:LyncSchedTask_Cred  -Authentication Credssp -ArgumentList @($UserSip.replace("sip:",""),$Destination,$Delay)

提示:请确保您没有在“Powershell双跳问题”中运行。SefaUtil将连接到前端服务器(我假设它是一个有CMS的服务器),以便在数据库中进行实际更改。(见我在TechNet上的回答:(由cwa.cloud提供)

参加派对有点晚,但我相信很多其他SfB管理员也会在这里挣扎

我就是这样做的:

Invoke-Command -ComputerName $Global:SefaUtilServer -ScriptBlock {&'C:\Program Files\Skype for Business Server 2015\ResKit\SEFAUtil.exe' '/server:epsachhst-lfe11.epsa.swisscom-mcc.local' $args[0] "/enablefwdnoanswer" "/setfwddestination:$($args[1])" "/callanswerwaittime:$($args[2])"} -Credential $Global:LyncSchedTask_Cred  -Authentication Credssp -ArgumentList @($UserSip.replace("sip:",""),$Destination,$Delay)

提示:请确保您没有在“Powershell双跳问题”中运行。SefaUtil将连接到前端服务器(我假设它是一个带有CMS的服务器)以在数据库中进行实际更改。(请参阅我在TechNet上的回答:(通过cwa.cloud)

这是我在下面提出的解决方案。 基本上,在SfB服务器上使用powershell创建一个批处理文件,然后使用psexec运行该文件以使用系统帐户(psexec已复制到服务器)。 确保在具有“servername”的位置插入自己的服务器名称,并使用具有足够权限的帐户运行脚本。然后使用正确的参数调用脚本

顺便说一句,我注意到如果转发已经到位,它可能会返回错误代码1

param ([string]$FwdUser,[string]$DestUser)

#skype for business phone forwarding
#create a batch file to run the command, run it as system with psexec and remove the batch file afterwards. sefautil does not cooperate with remote execution
$sefautilcmd = "`"C:\Program Files\Skype for Business Server 2015\ResKit\SEFAUtil.exe`" /Server:servername.headoffice.novationleasing.com.au " + $FwdUser + " /setfwddestination:" + $DestUser + " /enablefwdimmediate"
New-Item \\servername\c$\temp\tempfwd.bat
Set-Content \\servername\c$\temp\tempfwd.bat $sefautilcmd
Invoke-Command -ComputerName servername -ScriptBlock {C:\temp\psexec.exe -s -accepteula c:\temp\tempfwd.bat}
Remove-Item \\servername\c$\temp\tempfwd.bat

这就是我在下面提出的解决方案。 基本上,在SfB服务器上使用powershell创建一个批处理文件,然后使用psexec运行该文件以使用系统帐户(psexec已复制到服务器)。 确保在具有“servername”的位置插入自己的服务器名称,并使用具有足够权限的帐户运行脚本。然后使用正确的参数调用脚本

顺便说一句,我注意到如果转发已经到位,它可能会返回错误代码1

param ([string]$FwdUser,[string]$DestUser)

#skype for business phone forwarding
#create a batch file to run the command, run it as system with psexec and remove the batch file afterwards. sefautil does not cooperate with remote execution
$sefautilcmd = "`"C:\Program Files\Skype for Business Server 2015\ResKit\SEFAUtil.exe`" /Server:servername.headoffice.novationleasing.com.au " + $FwdUser + " /setfwddestination:" + $DestUser + " /enablefwdimmediate"
New-Item \\servername\c$\temp\tempfwd.bat
Set-Content \\servername\c$\temp\tempfwd.bat $sefautilcmd
Invoke-Command -ComputerName servername -ScriptBlock {C:\temp\psexec.exe -s -accepteula c:\temp\tempfwd.bat}
Remove-Item \\servername\c$\temp\tempfwd.bat

您是否检查了本地计算机上的事件日志以查找任何与powershell相关的错误?是否尝试了?尝试以下操作:
Invoke命令-ComputerName Computer01-ScriptBlock{Start Process-FilePath“C:\Program Files\Skype for Business Server 2015\ResKit\sefautil.exe”-ArgumentList“/服务器:sfbpool01.domain.local”,“sip:user1@domain.local", “/setfwddestination:user2@domain.local“,”/enablefwdimmediate“}
您遇到了什么错误?@vrdse-很遗憾没有错误。没有完全错误或标准的/?转储。您是否检查了本地计算机上的事件日志以查找任何与powershell相关的错误?是否尝试了?尝试此:
调用命令-ComputerName Computer01-ScriptBlock{启动进程-文件路径“C:\Program Files\Skype for Business Server 2015\ResKit\sefautil.exe”-ArgumentList”/Server:sfbpool01.domain.local”,“sip:user1@domain.local“,”/setfwddestination:user2@domain.local“,”/enablefwdimediate“}
您遇到了什么错误?@vrdse-遗憾的是没有错误。要么什么都没有,要么是一个标准的/?转储。嘿,一切正常。很高兴我能帮您找到正确的方法嘿,一切正常。很高兴我能帮您找到正确的方法