Software Inventory via Registry Error

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Christian Christian 1 year, 9 months ago.

  • Author
    Posts
  • #22699
    Profile photo of Christian
    Christian
    Participant

    Hi all.

    I am trying to create an exportable report of software installed on systems, either servers or pc's via the registry with the following line of commands and I am not sure where I am failing. I have researched online, and through forums and from what I've read it should be working. Any guidance would be appreciated. Thank you.

    "invoke-command -scriptblock {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate} -ComputerName (Get-content test1.txt) | export-csv software.csv" – is what I am using and below is the error I get.

    Invoke-Command : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the
    command again.
    At line:1 char:202
    + ... -ComputerName (Get-content test1.txt) | Export-Csv software.csv
    + ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand

  • #22701
    Profile photo of Greg Altman
    Greg Altman
    Member

    Hi,
    Try putting the full path to test1.txt . I tested your code and noticed that since full paths aren't used the script pulls from /writes to the directory the ISE is pointed at currently.

  • #22703
    Profile photo of Christian
    Christian
    Participant

    Hello. Thank you very much for your reply. I have made the change to the line and it is still generating the same error. The test1.txt file does contain valid computer names pulled from AD. If I replace the (get-content h:\test1.txt) with a single computer name without brackets it does work.

    PS H:\> invoke-command -scriptblock {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate} -ComputerName (Get-content H:\test1.txt) | Export-Csv software.csv
    Invoke-Command : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the
    command again.
    At line:1 char:202
    + ... -ComputerName (Get-content H:\test1.txt) | Export-Csv software.csv
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand

  • #22704
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    You probably have blank lines in your text file (possibly just one blank line at the end). This is a common problem, but it's easy to filter out the blanks:

    $computerNames = Get-Content H:\test1.txt | Where-Object { $_ }
    Invoke-Command -ComputerName $computerNames # etc
    
  • #22709
    Profile photo of Christian
    Christian
    Participant

    HI Dave. Thank you very much for the help! You were right, there was a blank space at the end of the list. I thought I had removed them all, apologies. I have not yet tried your suggestion for filtering out the spaces but I'm eager to try it out and see the results. Thank you again.

You must be logged in to reply to this topic.