我们正在尝试获取供应商的命令行远程执行并将其转换为 PowerShell 2.0。但是,由于变量的设置方式,我们似乎无法让命令远程运行。它们是空格分隔的,而不是逗号分隔的。我们创建了一个表单来获取变量的输入。有没有人有关于如何让它在 PowerShell 中工作的建议?谢谢!瑞德
#Call the Function
GenerateForm
#Attempting to translate Dos command below to Powershell
#winrs -r:$ServerName -nop -d:"C:\Program Files (x86)\PaperCut NG\server\bin\win\" server-command.exe $Command $Varible1 $Varible2 $Varible3
#cd C:\Program Files\PaperCut NG\server\bin\win\server-command rename-printer oldprintserver oldqueuename newprintserver newqueuename
#From: http://www.papercut.com/kb/Main/HowToRenameAPrinter
#Also: http://www.papercut.com/kb/Main/CallingServerCommandRemotely
#Server Commands List: http://www.papercut.com/products/ng/manual/apdx-tools.html
#Have tried below and many others:
#Invoke-Command -computername $ServerName -scriptblock {'C:\Program Files (x86)\PaperCut NG\server\bin\win\server-command.exe rename-printer $OldPrintServer $OldQueueName $NewPrintServer $NewQueueName}
#Invoke-Command -Authentication Kerberos -computername $ServerName -scriptblock {"C:\Program Files (x86)\PaperCut NG\server\bin\win\server-command.exe"} -ArgumentList {param(rename-printer[, $OldPrintServe][, $OldQueueName][, $NewPrintServer][, $NewQueueName])}
#Invoke-Command -computername $ServerName -scriptblock {cd 'C:\Program Files (x86)\PaperCut NG\server\bin\win\'; .\'server-command.exe rename-printer' $OldPrintServer $OldQueueName $NewPrintServer $NewQueueName}
#Invoke-Command -computername $ServerName -scriptblock {cd 'C:\Program Files (x86)\PaperCut NG\server\bin\win\'; .\'server-command.exe' + ' rename-printer' + ' ' + $OldPrintServer + ' ' + $OldQueueName + ' ' + $NewPrintServer + ' ' + $NewQueueName}
#Invoke-Command -computername $ServerName &"C:\Program Files (x86)\PaperCut NG\server\bin\win\server-command.exe" "rename-printer" "$OldPrintServer" "$OldQueueName" "$NewPrintServer" "$NewQueueName"
#Invoke-Command -computername $ServerName &{"C:\Program Files (x86)\PaperCut NG\server\bin\win\server-command.exe" "rename-printer" "$OldPrintServer" "$OldQueueName" "$NewPrintServer" "$NewQueueName"}
Invoke-Command -computername $ServerName -scriptblock {&"C:\Program Files (x86)\PaperCut NG\server\bin\win\server-command.exe" "rename-printer" "$OldPrintServer" "$OldQueueName" "$NewPrintServer" "$NewQueueName"}
Read-Host "Press ENTER to continue"