none
Error in powershell script RRS feed

  • General discussion

  • Hello Experts!!!

    I have created the below powershell script to fix the software updates unknown compliance machines, but it was throwing the below error.

    I am new to powershell and i could not fix the error msg form the script.Please help to fix the error from the script.

    $computer = $env:COMPUTERNAME $namespace = "ROOT\ccm\SoftwareUpdates\UpdatesStore" $classname = "CCM_UpdateStatus"

    [bool]$f= $false $uniqueidall = Get-WmiObject -Namespace $namespace -Query "select uniqueid from CCM_updatestatus where title like '%2019-08%' and status = 'installed'" foreach ( $uniqueid in $uniqueidall) { $statemsg = (Get-WmiObject -namespace "root\CCM\StateMsg" -query "select messagesent from CCM_StateMsg where TopicID = "$uniqueid""). if($statemsg -eq 'True') { Get-WmiObject -namespace "root\CCM\StateMsg" -query "select * from CCM_StateMsg where TopicID = "$uniqueid"" | Set-WmiInstance -Arguments @{MessageSent = $f} Write-output "Resent the Assignment Compliance to the MP for the client" } }

    Error message getting when i run the script.

    Get-WmiObject : A positional parameter cannot be found that accepts argument 'CCM_UpdateStatus.UniqueId="f29f309a-cb23-44f5-b3cb-22710a956c1f"'.

    At line:9 char:14
    + ... statemsg = (Get-WmiObject -namespace "root\CCM\StateMsg" -query "sele ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Get-WmiObject], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    THANKS SURESH M


    • Edited by Suresh Muniyan Thursday, September 12, 2019 2:00 PM Modifying content
    • Changed type Bill_Stewart Tuesday, April 14, 2020 1:34 PM
    • Moved by Bill_Stewart Tuesday, April 14, 2020 1:34 PM Abandoned
    Thursday, September 12, 2019 1:55 PM

All replies

  • Please read this first:

    This forum is for scripting questions rather than script requests


    -- Bill Stewart [Bill_Stewart]

    Thursday, September 12, 2019 1:57 PM
  • Please read this first:

    This forum is for scripting questions rather than script requests


    -- Bill Stewart [Bill_Stewart]

    Ok fine...Thanks for the clarification.

    Can you please let me know what is the below error and how to fix it when we getting it.

    Get-WmiObject : A positional parameter cannot be found that accepts argument


    THANKS SURESH M

    Thursday, September 12, 2019 2:04 PM
  • The error means what it says. You are not passing a correct parameter to the Get-WmiObject cmdlet.

    If you don't understand the error message, I would recommend starting to learn PowerShell (there is a Learn link at the top of this forum). Start with the basics. Your time investment will be rewarded. I would not recommend guesswork.


    -- Bill Stewart [Bill_Stewart]

    Thursday, September 12, 2019 2:33 PM
  • Replace these statements:

    Get-WmiObject -namespace "root\CCM\StateMsg" -query "select messagesent from CCM_StateMsg where TopicID = "$uniqueid""

    With these:

    Get-WmiObject -namespace "root\CCM\StateMsg" -query 'select messagesent from CCM_StateMsg where TopicID = "$uniqueid"'

    You can either use single quotes withing double quotes or vice versa, but not the same at a time. 

    ""Uniqueid"" - Won't Work

    '"Uniqueid"' -  Will Work

    Thursday, September 12, 2019 3:36 PM
  • You cannot use single quotes with a variable, The outer quotes must be double.

    Get-WmiObject CCM_StateMsg -Filter "TopicID='$uniqueid'" -namespace root\CCM\StateMsg


    \_(ツ)_/

    Thursday, September 12, 2019 5:11 PM
  • Replace these statements:

    Get-WmiObject -namespace "root\CCM\StateMsg" -query "select messagesent from CCM_StateMsg where TopicID = "$uniqueid""

    With these:

    Get-WmiObject -namespace "root\CCM\StateMsg" -query 'select messagesent from CCM_StateMsg where TopicID = "$uniqueid"'

    You can either use single quotes withing double quotes or vice versa, but not the same at a time. 

    ""Uniqueid"" - Won't Work

    '"Uniqueid"' -  Will Work

    Thanks for your response..the script worked after i changed the quotes, but i still struck with my requirements.

    i have created a script to change the attribute name 'messagesent' which is available in class 'CCM_StateMsg' and namespace 'root\CCM\StateMsg' to 'false' from true.

    Even though the script executed successfully without any error still the attribute messagesent value is 'true', please help me to change the attribute to 'false'



    THANKS SURESH M

    Thursday, September 12, 2019 8:14 PM
  • Get-WmiObject CCM_StateMsg -Filter "TopicID='$uniqueid'" -namespace root\CCM\StateMsg | 
         Select @{n='MessageSent';e={$_.MessageSent -eq 'true'}}


    \_(ツ)_/


    • Edited by jrv Thursday, September 12, 2019 10:40 PM
    Thursday, September 12, 2019 8:40 PM
  • jrv - do a little bit better on your proofreading :)

    Should be:


    Get-WmiObject CCM_StateMsg -Filter "TopicID='$uniqueid'" -Namespace root\CCM\StateMsg | 
      Select-Object @{n='MessageSent';e={$_.MessageSent -eq 'true'}}
    

    (change l to ; - I also shortened the expression a bit - no need for the "if")


    -- Bill Stewart [Bill_Stewart]

    Thursday, September 12, 2019 10:19 PM
  • Since I didn't know what was in the property it was intended to be an example of "how" not a solution.

    You are right. The "if/else"  is not needed.  I ususally catch that bhut didn't this time.  

    Thanks Bill.


    \_(ツ)_/

    Thursday, September 12, 2019 10:39 PM
  • I have written code like that before and thought to myself, "this seems too hard" (and then I realized I was doing it the hard way).


    -- Bill Stewart [Bill_Stewart]

    Friday, September 13, 2019 2:08 PM