none
Error on script RRS feed

  • Question

  • 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:02 PM Modifying content
    Thursday, September 12, 2019 1:54 PM

Answers

  • This is PowerShell specific.

    You need to either escape your double-quotes in line 9 or use single quotes. You also need to get rid of the trailing period:

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


    Jason | https://home.configmgrftw.com | @jasonsandys

    • Marked as answer by Suresh Muniyan Sunday, September 15, 2019 1:49 PM
    Thursday, September 12, 2019 2:53 PM
  • i have rewrite the script with few modification and it works now.

    thanks all for your inputs and thoughts.

    $namespace = "ROOT\ccm\SoftwareUpdates\UpdatesStore"
    $classname = "CCM_UpdateStatus"
    $namespace1  = "root\CCM\StateMsg"
    $clasname1 = "CCM_StateMsg"
    
    
    [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 $namespace1 -query "select * from CCM_StateMsg where TopicID='$($uniqueid.UniqueId)' "
        if($statemsg.MessageSent -eq 'True')
        { 
            Get-WmiObject -namespace $namespace1 -query "select * from CCM_StateMsg where TopicID='$($uniqueid.UniqueId)' " | Set-WmiInstance -Arguments @{MessageSent = $f}
            Write-output "Resent the Assignment Compliance to the MP for the client"
        }
    }


    THANKS SURESH M

    • Marked as answer by Suresh Muniyan Saturday, September 14, 2019 9:35 AM
    Saturday, September 14, 2019 9:35 AM

All replies

  • This is PowerShell specific.

    You need to either escape your double-quotes in line 9 or use single quotes. You also need to get rid of the trailing period:

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


    Jason | https://home.configmgrftw.com | @jasonsandys

    • Marked as answer by Suresh Muniyan Sunday, September 15, 2019 1:49 PM
    Thursday, September 12, 2019 2:53 PM
  • This is PowerShell specific.

    You need to either escape your double-quotes in line 9 or use single quotes. You also need to get rid of the trailing period:

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


    Jason | https://home.configmgrftw.com | @jasonsandys

    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:16 PM
  • Hello,
     
    Thanks for posting in TechNet.
     
    Try using the following method instead.
     
    $statemsg = Get-WmiObject -namespace 'root\CCM\StateMsg' -query 'select * from CCM_StateMsg where TopicID = "$uniqueid"'
    
    if($statemsg.MessageSent -eq $true){ 
    $statemsg.MessageSent = $false
    $statemsg.put()}
     
    Hope my answer could help you and look forward to your feedback.
     
    Best Regards,
    Ray

     

    Please remembers to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, September 13, 2019 9:27 AM
  • i have rewrite the script with few modification and it works now.

    thanks all for your inputs and thoughts.

    $namespace = "ROOT\ccm\SoftwareUpdates\UpdatesStore"
    $classname = "CCM_UpdateStatus"
    $namespace1  = "root\CCM\StateMsg"
    $clasname1 = "CCM_StateMsg"
    
    
    [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 $namespace1 -query "select * from CCM_StateMsg where TopicID='$($uniqueid.UniqueId)' "
        if($statemsg.MessageSent -eq 'True')
        { 
            Get-WmiObject -namespace $namespace1 -query "select * from CCM_StateMsg where TopicID='$($uniqueid.UniqueId)' " | Set-WmiInstance -Arguments @{MessageSent = $f}
            Write-output "Resent the Assignment Compliance to the MP for the client"
        }
    }


    THANKS SURESH M

    • Marked as answer by Suresh Muniyan Saturday, September 14, 2019 9:35 AM
    Saturday, September 14, 2019 9:35 AM
  • When people offer to give up their free time to help you with an issue and they provide you an answer that resolves your issue, the least you could do is actually mark their suggestion as the answer. You get nothing from marking your own answer as the correct answer.

    Have a nice day.


    Richard Knight | Collection Refresh Manager | Automate detection rules for patch \ msp files | Twitter

    Saturday, September 14, 2019 10:18 AM
  • When people offer to give up their free time to help you with an issue and they provide you an answer that resolves your issue, the least you could do is actually mark their suggestion as the answer. You get nothing from marking your own answer as the correct answer.

    Have a nice day.


    Richard Knight | Collection Refresh Manager | Automate detection rules for patch \ msp files | Twitter

    Hi Richard,

    Yeah you are right...
    I dont get anything if i marked mine as answer.
    But that was the exact answer of my question and so i marked as answer to make other know the exact answer.
    yeah as per your commands i would have marked as an answer if it was the exact answer for my question.

    That was reason i was thanked everyone who has responded in this thread.


    THANKS SURESH M

    Sunday, September 15, 2019 1:49 PM