none
Software List RRS feed

  • Question

  • Hi , I have following script to search domain root for computer and list the installed applications, while output is to console having difficulty getting it to a CSV file. Can anyone please help ?

    $datetime = Get-Date -Format "ddMMMyyyy"
    $strCategory = "computer";

    # Connect to root of domain
    $objDomain = New-Object System.DirectoryServices.DirectoryEntry;
    # AD Searcher object
    $objSearcher = New-Object System.DirectoryServices.DirectorySearcher;
    # Set Search to root of domain
    $objSearcher.SearchRoot = $objDomain;
    # Search filter
    $objSearcher.Filter = ("(objectCategory=$strCategory)");

    $colProplist = "name";
    foreach ($i in $colPropList)
    {
    $objSearcher.PropertiesToLoad.Add($i);
    }

    $colResults = $objSearcher.FindAll();


    # Add column headers

    Add-Content "$Env:USERPROFILE\Software_List $datetime.csv" "Computer,DisplayName,DisplayVersion,Publisher";

    foreach ($objResult in $colResults)
    {
    $objComputer = $objResult.Properties;
    $computer = $objComputer.name;

    $ipAddress = $pingStatus.ProtocolAddress;
    # Ping the computer
    $pingStatus = Get-WmiObject -Class Win32_PingStatus -Filter "Address = '$computer'";

    if($pingStatus.StatusCode -eq 0)
    {
    Write-Host -ForegroundColor Green "Ping Reply received from $computer.";

    write-host "Connecting to $computer..."

    $colItems = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* `
    -Computername $computer

    write-host "#############################"
    write-host "Computer: " $computer
    write-host "#############################"

    foreach ($objItem in $colItems)
    {
    Write-Host "Computer: "$objComputer.name
    $caption = $objItem.Computername;
    write-host "Displayname: " $objItem.displayname
    $caption = $objItem.Displayname;
    write-host "Version: " $objItem.DisplayVersion
    $caption = $objItem.Description;
    write-host "Publisher: " $objItem.Publisher
    $caption = $objItem.Publisher;
    }
    }

    Add-Content "$Env:USERPROFILE\software_list $datetime.csv" "$Computername,$Displayname,$Displayversion"


    }

    else

    {
    Write-Host -ForegroundColor Red "No Ping Reply received from $computer"
    }


    Yasar

    Tuesday, July 15, 2014 5:23 AM

Answers

All replies

  • Hi Yasar,

    try this instead of that foreach loop writing the results to the console:

    $objItems | Export-Csv "C:\ExampleFolder\Example $computer.csv"

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Tuesday, July 15, 2014 10:54 AM
  • What you are trying to do cannot be done this way.

    This line is not possible:

    Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* Computername $computer

    That CmdLet does not have -computername as a parameter.


    ¯\_(ツ)_/¯

    Tuesday, July 15, 2014 1:59 PM
  • Start with this and add the remote registry calls or use PowerShell remoting.

    $datetime = Get-Date -Format "ddMMMyyyy"
    $searcher=[adsisearcher]'objectcategory=computer' 
    $searcher.PropertiesToLoad.Add('name')
    
    $results=$searcher.FindAll() |
        ForEach-Object{
            $computer=$_.Properties['name']
            if(Test-Connection $computer -Quiet -Count 1){
                Write-Host -ForegroundColor Green "Ping Reply received from $computer."
                write-host "`tConnecting to $computer..."
                #Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* 
                # replace this with remote registry calls.
                write-host "`t#############################"
                write-host "`tComputer: " $computer
                write-host "`t#############################"
            }else{
                Write-Host -ForegroundColor Red "No Ping Reply received from $computer"
            }
        }
    


    ¯\_(ツ)_/¯

    Tuesday, July 15, 2014 2:07 PM
  • I would add that it's unnecessary to reinvent the wheel. There is a search box at the top of this page.

    Enter the search terms "list installed applications'' and press Enter.

    This will bring up a list of forum posts that talk about listing installed applications.

    One example:

    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/82b8aaa0-dcfa-4c75-b960-e3da1d2d4cab/

    There is also a searchable repository of pre-written scripts (link right at the top of this page).

    (Don't be helpless: You can find information too, if you try.)


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Toros72 Wednesday, July 23, 2014 4:11 AM
    Tuesday, July 15, 2014 2:58 PM
    Moderator
  • Here is a simple remoting function that can get a remote value.

    http://1drv.ms/1jMhRYH


    ¯\_(ツ)_/¯


    • Edited by jrv Tuesday, July 15, 2014 3:23 PM
    Tuesday, July 15, 2014 3:23 PM