none
Powershell add a value to a variable RRS feed

  • Question

  • Hello,

    i am having a very simple Problem and i find now solution:

    In Line 2 I write some objects into the variable $vApplictaionDetect

    In Line 3i want to add some more objects (it my script it will overwrite the current content)

    $vApplicationName = 'Dassault' 
    $vApplictaionDetect = Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.Publisher -like $vApplicationName+"*"}
    $vApplictaionDetect = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.Publisher -like $vApplicationName+"*"})

    Friday, February 20, 2015 1:03 PM

Answers

  • i got it

    $vApplicationName = 'Dassault' $vApplictaionDetect = @( ((Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.Publisher -like $vApplicationName+"*"}).PSChildName) , ((Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.Publisher -like $vApplicationName+"*"}).PSChildName)

    )



    • Marked as answer by Strahle_fz Wednesday, February 25, 2015 7:16 AM
    • Edited by Strahle_fz Wednesday, February 25, 2015 7:17 AM code
    Wednesday, February 25, 2015 7:16 AM

All replies

  • Noone who can help me?
    Tuesday, February 24, 2015 6:26 PM
  • Are you saying you want to add more information to the variable, without overwriting what's already in the variable? If so, then use the += assignment operator. This will append data to what's already in the variable. As you know, using the = assignment operator will overwrite anything already stored in the variable.
    Tuesday, February 24, 2015 6:29 PM
  • Hello,

    thx for your reply.

    When i Change to += I am getting the following error:

    Method invocation failed because [System.Management.Automation.PSObject] doesn't contain a method named 'op_Addition'.

       + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException

        + FullyQualifiedErrorId : MethodNotFound

    Wednesday, February 25, 2015 5:39 AM
  • i got it

    $vApplicationName = 'Dassault' $vApplictaionDetect = @( ((Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.Publisher -like $vApplicationName+"*"}).PSChildName) , ((Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.Publisher -like $vApplicationName+"*"}).PSChildName)

    )



    • Marked as answer by Strahle_fz Wednesday, February 25, 2015 7:16 AM
    • Edited by Strahle_fz Wednesday, February 25, 2015 7:17 AM code
    Wednesday, February 25, 2015 7:16 AM