none
Checking if Control Panel Item Exists RRS feed

  • Question

  • hello all,

        I am trying to check to see if a ControlPanel item exists or not.  The command I am running is: 

    Get-ControlPanelItem -Name "Configuration Manager" -errorvariable blah
    but it is not being captured into the variable blah.  Please advise.
    Monday, June 17, 2019 5:26 PM

Answers

All replies

  • What is not being capture. You have not assigned the results to any variable.


    \_(ツ)_/

    Monday, June 17, 2019 7:26 PM
    Moderator
  • Appears to be working for me.

    Monday, June 17, 2019 8:48 PM
  • This is what I am getting.

    Update:

    I noticed you added more to your command syntax at the end.  Once I added that, then yeah, it works fine.  Ty

    • Edited by lonesoac01 Wednesday, June 19, 2019 12:10 PM Ooops
    Wednesday, June 19, 2019 12:07 PM
  • This is what I am getting.


    I get the same thing. I just added the -erroraction to suppress the error on the call. If you interrogate the $blah variable you will see that it contains the error. 

    Wednesday, June 19, 2019 2:24 PM
  • You are all over the map with this.  What is you question?  Why are you using an errorvariable.

    Here is how to test for an item.

    if (Get-ControlPanelItem -Name "Configuration Manager" -ErrorAction 0) {
        Write-Host 'Item found'
    }else{
        Write-Host 'Item not found'
    }

    Or

    Try{
        Get-ControlPanelItem -Name 'Configuration Manager' -ErrorAction Stop
        Write-Host 'Item found'
    }
    Catch{
        Write-Host 'Item not found'
    }


    \_(ツ)_/

    Wednesday, June 19, 2019 2:31 PM
    Moderator