#########################################################install-product.ps1(v1)################################################################## #(Auteur: Mickael Hornung) # # # # Ce script permet de faire une recherche local ou distante d'un programme sur un poste # # Si aucun paramètre n'est spécifié, la recherche se fait sur le poste local et affiche la liste de tout les programmes installés # # Exemple d'utilisation : ./install-product.ps1 (recherche de tout les programmes installés sur le poste local # # ./install-product.ps1 -H "poste_distant" (recherche tout les programmes installés sur le poste distant) # # ./install-product.ps1 -H "poste_distant" -P "Skype" (recherche si Skype est installé sur le poste distant) # # ./Install-product.ps1 -P "skype' -L liste.txt (recherche de skype parmis une liste de poste) # # # ################################################################################################################################################## Param([string]$P="", [string]$H="", [string]$L="") if($L -ne "") { [Array]$list = get-content $L foreach ($computer in $list) { ./install-product2.ps1 -P $($P) -H $($computer) } } if(($H -like "") -or ($H -like "localhost") -or ($H -like "127.0.0.1") -and ($L -eq "")) { if($P -eq "") { $produits = Get-ChildItem hklm:\software\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $_.pspath} $produits | Select-Object @{e={$_.DisplayName};n='Nom'},@{e={$_.PSChildName};n='PSChildName'},@{e={$_.UninstallString};n='Uninstall'} } else { $produits = Get-ChildItem hklm:\software\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $_.pspath} $produits | Select-Object @{e={$_.DisplayName};n='Nom'}, @{e={$_.UninstallString};n='Uninstall'} | Where-Object {$_.Nom -match $($P)} } } else { if($P -eq $NULL) { $RemoteConnexion=[microsoft.win32.registrykey]::openremotebasekey("LOCALMACHINE",$H) $Values=$RemoteConnexion.opensubkey("software\microsoft\windows\currentversion\uninstall") $Values.GetSubKeyNames() } else { $match=0 $RemoteConnexion=[microsoft.win32.registrykey]::openremotebasekey("LOCALMACHINE",$H) $Values=$RemoteConnexion.opensubkey("software\microsoft\windows\currentversion\uninstall") $Result=$Values.GetSubKeyNames() $Nb_Entry=$Result.Count Write-Host `n Write-Host "-- $H --" -foregroundcolor green for($i=0;$i -lt [int]$($Nb_Entry);$i++) { $Values=$RemoteConnexion.opensubkey("software\microsoft\windows\currentversion\uninstall\$($Result[$i])") $PName=$Values.GetValue("DisplayName") if(($PName -match $($P)) -and ($PName -ne $NULL)) { $match=1 $PVersion=$Values.GetValue("DisplayVersion") $PUninstallString=$Values.GetValue("UninstallString") Write-Host "--------------------------------" Write-Host "Nom: $($PName)" Write-Host "Version: $($PVersion)" Write-Host "Desinstallation: $($PUninstallString)" Write-Host "--------------------------------" } } if($($match) -eq 0) { Write-Host "--------------------------------" Write-Host "Aucun résultat" Write-Host "--------------------------------" } } }