首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >rdesktop外壳转义问题

rdesktop外壳转义问题
EN

Stack Overflow用户
提问于 2012-06-16 21:56:26
回答 3查看 549关注 0票数 1

我试着发送这个:

代码语言:javascript
复制
Get-WmiObject Win32_PNPEntity |Where{$_.DeviceID.StartsWith("PCI\VEN_10DE") -or $_.DeviceID.StartsWith("PCI\VEN_1002")}

在rdesktop上,如:

代码语言:javascript
复制
rdesktop -a8 209.** -u ** -p ** -s "cmd.exe /K powershell.exe Get-WmiObject Win32_PNPEntity |Where{\$_.DeviceID.StartsWith("PCI\VEN_10DE") -or $_.DeviceID.StartsWith("PCI\VEN_1002")}"

但是windows的shell写道:

代码语言:javascript
复制
'Where{$_.DeviceID.StartsWith' is not recognized as an internal or externa....

我做错了什么?

EN

回答 3

Stack Overflow用户

发布于 2012-06-17 04:36:39

为什么不使用powershell wmi远程处理?

代码语言:javascript
复制
$cred = get-credential
Get-WmiObject Win32_PNPEntity -computerName MyRemoteComputerName - credential $cred |Where{$_.DeviceID.StartsWith("PCI\VEN_10DE") -or $_.DeviceID.StartsWith("PCI\VEN_1002")} 

只有当运行powershell的实际用户不是远程机器的管理员时,才需要-credential

票数 1
EN

Stack Overflow用户

发布于 2012-06-18 03:43:12

嗨,我需要做一些像这样的事情,所以我写了一些代码,可以发送任何ps代码到远程计算机,并在您的pc上的ps窗口中显示结果。

只需记住在两台pc上启用powershell远程处理即可。

代码语言:javascript
复制
function remote-pscode ($ServerName,$UserName,$password,$PSCode)
{


$global:RemoteCode = $args[0]

Write-Host $RemoteCode
$conprops = (Get-Host).UI.RawUI
$buffsize = $conprops.BufferSize
$buffsize.Height = 800
$conprops.BufferSize= $buffsize

# Set the user name you would like to use for the connection
$global:RemoteUserName = $UserName
$global:RemoteServerName = $ServerName


# Set the password you would like to use for the connection
# Check to see if you have a file on you drive c:\cred.txt with a password to use in it,if you don't it will create one
# for you and ask you for the password you would like to use 


$global:RemotePassword = convertto-securestring $password -AsPlainText -Force
$global:credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $RemoteUserName,$RemotePassword



#Create a connection to the remote computer , put a list of IPAddresses or Computer Names.
$global:session = new-PSSession -ComputerName $RemoteServerName -Credential $credentials


$ScriptBlock = $executioncontext.invokecommand.NewScriptBlock($RemoteCode)

invoke-command -Session $session -ScriptBlock $ScriptBlock


#Close the sessions that where created     
$global:closesession = Get-PSSession
Remove-PSSession -Session $closesession

}

remote-pscode -ServerName "NameOfRemotePC" -UserName "UserName" -password "password"  -PSCode "any powershell code you want to send to the remote pc"
票数 1
EN

Stack Overflow用户

发布于 2012-06-16 22:10:35

这里有几件事:将PS命令放在script block (或脚本)中。另外,为什么不简单地使用wmic.exe呢?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11064033

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档