将命令行参数传递给命令

时间:2014-10-14 04:54:00

标签: powershell wmi

我需要传递一个powershell脚本参数作为WMI查询的一部分,但它会抛出错误。

param (
    [Parameter(Mandatory=$true)][string]$user,
    [Parameter(Mandatory=$true)][string]$pwd
)

$harryuser = Get-WmiObject -Namespace Root\Harry -ComputerName myserver -query "select * from 
UserList where name = $user"

harryuser.SetPassword($pwd)

错误是无效的查询

1 个答案:

答案 0 :(得分:1)

尝试像这样在$ user附近添加单引号。

"从UserList中选择*,其中name =' $ user'"