PowerShell WMI function call with multiple variable

0

I want to call a WMI method which is taking one string as input , one integer as input and one integer as output.

Here is the Current Example:

$obj=Get-WmiObject -class "class1" -namespace "space1" $obj| Invoke-wmiMethod -name fun -ArgumentList $devUUID , $role , $status

Shantanu Kumar

Posted 2016-02-22T16:29:11.517

Reputation: 9

Question was closed 2016-02-26T00:14:48.303

1

You should provide a sample of what you're hoping to use/do and why it's not working. Additionally, always search and see if existing articles out there explain how to do things, for instance this first google result: https://technet.microsoft.com/en-us/library/ee176860.aspx

– Abraxas – 2016-02-22T16:48:59.003

$obj=Get-WmiObject -class "class1" -namespace "space1" $obj| Invoke-wmiMethod -name fun -ArgumentList $devUUID , $role , $status – Shantanu Kumar – 2016-02-22T16:58:52.213

and there is no need of complter name because i am working on current host – Shantanu Kumar – 2016-02-22T17:01:10.073

$obj=Get-WmiObject -class "class1" -namespace "space1"

$obj| Invoke-wmiMethod -name fun -ArgumentList $devUUID , $role , $status – Shantanu Kumar – 2016-02-22T17:59:45.737

You have an example, but it isn't clear what this is or how it relates. Is it sample code you found somewhere? If this what you're trying to use and it isn't giving you what you want? If so, what result do you want, what does this code give you, and how is the result not satisfactory? – fixer1234 – 2016-02-25T06:33:27.677

Answers

2

What exactly are you trying to achieve here?

A simple Get-WMIObject and a couple of Read-Hosts should do what you need it to:

$className = Read-Host "Enter Class Name"
$computerName = Read-Host "Enter Computer Name"
if ([string]::IsNullOrWhitespace($computerName)) {
    $computerName = "."
}

Get-WmiObject -ComputerName $computerName -Class $className

Bolt in a bit of extra error checking so that you aren't trying to check an invalid class name etc and you should be good to go. Example below: enter image description here


You can also contatenate inside a command strings like so:

Get-WMIObject -Class ($string1 + "32" + "_" + $string2) -ComputerName "."

(in this case, $string1 contains "WIN" and $string2 contains "BIOS")

Things in brackets are processed before it's parent command. You can even go deeper and do brackets within brackets.. PowerShell will start at the deepest level and work it's way out until it hits the parent command and then execute the fully computed strings.

Fazer87

Posted 2016-02-22T16:29:11.517

Reputation: 11 177

you are not getting mi actual problem – Shantanu Kumar – 2016-02-22T17:02:27.247

i have problem in passing multiple input arguments but you have not discuss about this – Shantanu Kumar – 2016-02-22T17:57:18.100

What is the actual problem? Supply an example – Smeerpijp – 2016-02-22T21:47:58.340

[string]$UUID="mpx.msbha0:C2:T0:L0" [int]$role=0 $wmiConnection=[WMICLASS]"root\wmi:myclass" $methodParameter=$wmiConnection.psbase.getmethodsparameter("Myfunction") – Shantanu Kumar – 2016-02-23T05:06:04.923

' [string]$UUID="mpx.msbha0:C2:T0:L0" ' ' [int]$role=0 ' ' $wmiConnection=[WMICLASS]"root\wmi:myclass" ' ' $methodParameter=$wmiConnection.psbase.getmethodsparameter("Myfunction") ' ' $methodParameter.UUID=$UUID ' ' $methodParameter.role=$role ' '$wmiconnection.psbase.invokeMethod("Myfunction",$methodParameter,$null)'

I am getting ' Exception calling InvokeMethod with 3 arguments: "Invalid method parameter" – Shantanu Kumar – 2016-02-23T05:13:25.943

Edit the examples in your opening posts with correct formats please, this is not very readable – Smeerpijp – 2016-02-23T08:40:58.957