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

时间:2018-02-27 15:30:29

标签: 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@domain.local /enablefwdimmediate

这可以在任何机器上运行时运行良好,但我真的很难通过远程PowerShell运行它。

我通过invoke-command尝试的任何命令都会给我一个标准的/?响应或者根本没有。我已经通过-ArgumentList作为变量传递了args,作为我能想到的任何东西,它只是不起作用。

是什么让事情变得更加有条理,好像你没有管理员权限,你就不会得到任何结果。该命令必须以管理员身份运行。现在我可以很容易地将管理模式检查器放入我的脚本中,但是如果它像管理员一样容易发送命令我将接受它。

任何帮助都会受到大力赞赏。

3 个答案:

答案 0 :(得分:1)

@ 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 }

这几乎肯定是一个漫长的方式,但它确实有效。

感谢您给我一个全新的视角。

答案 1 :(得分:0)

聚会晚了一点,但是我敢肯定,很多其他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 Double Hop问题”中运行。 SefaUtil将与前端服务器建立连接(我假设这是位于CMS的服务器),以在数据库中进行实际更改。 (请参阅我在TechNet上的回答:https://social.technet.microsoft.com/Forums/office/en-US/5d4c4f90-1b40-4742-ae4b-c2e1a62a0adb/running-sefautil-remotely?forum=lyncdeploy#da6b82b9-cada-420b-a7a7-2110c0ed2280(由cwa.cloud提供)

答案 2 :(得分:0)

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

顺便说一句,我注意到如果转发已经到位,它可以返回错误代码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