Get Remote Computer Install Software

#requires -Version 2

function Get-Software
{
    param
    (
        [string]
        $DisplayName='*',

        [string]
        $UninstallString='*',

        [string[]]
        $ComputerName
    )

    [scriptblock]$code =
    {

        param
        (
        [string]
        $DisplayName='*',

        [string]
        $UninstallString='*'

        )
      $keys = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*',
       'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'

      $result=Get-ItemProperty -Path $keys |
      Where-Object { $_.DisplayName } |
      Select-Object -Property DisplayName, DisplayVersion, UninstallString |
      Where-Object { $_.DisplayName -like $DisplayName } |
      Where-Object { $_.UninstallString -like $UninstallString }

      $result
      #$f=$result -contains '*autodesk*'
    }
    if ($PSBoundParameters.ContainsKey('ComputerName'))
    {
        Invoke-Command -ScriptBlock $code -ComputerName $ComputerName -ArgumentList $DisplayName, $UninstallString
    }
    else
    {
        & $code -DisplayName $DisplayName -UninstallString $UninstallString
    }
}

#Get-Software -ComputerName "CNKLCNSHSR2001"


Import-Csv "C:\Temp\Logs\pcname.csv" |
foreach{
    try{
        Get-Software -ComputerName $_."pcname"
        
    }
    catch{
        
    }
}|
export-csv  C:\Temp\Logs\pcname_Result.csv -notypeinformation 

  

posted @ 2018-11-22 15:01  Javi  阅读(154)  评论(0编辑  收藏  举报