1

I'm trying to send this:

Get-WmiObject Win32_PNPEntity |Where{$_.DeviceID.StartsWith("PCI\VEN_10DE") -or $_.DeviceID.StartsWith("PCI\VEN_1002")}

over rdesktop like:

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")}"

But windows' shell says:

'Where{$_.DeviceID.StartsWith' is not recognized as an internal or externa....

What am I doing wrong?

4

3 回答 3

1

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

只要记住在两台电脑上启用 powershell 远程处理。

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"
于 2012-06-17T19:43:11.803 回答
1

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

$cred = get-credential
Get-WmiObject Win32_PNPEntity -computerName MyRemoteComputerName - credential $cred |Where{$_.DeviceID.StartsWith("PCI\VEN_10DE") -or $_.DeviceID.StartsWith("PCI\VEN_1002")} 

-credential仅当运行 powershell 的实际用户不是远程计算机的管理员时才需要。

于 2012-06-16T20:36:39.410 回答
0

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

于 2012-06-16T14:10:35.147 回答