Question Install-product.ps1

Plus d'informations
il y a 14 ans 1 mois #6275 par Mickael Hornung
Bonjour à tous,
Voici un script qui permet de connaitre les programmes installés sur un poste local ou distant.
J'interroge le registre car en passant par WMI avec la classe win32_product certains programmes sont absent.
Vous trouverez sûrement des améliorations pouvant y être apportées car je l'ai fait pour un besoins immédiat en prod... (tout mes postes sont sur XP, donc sur vista ou Windows 7 ça peut merder :P )

[code:1]
#########################################################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-product.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 \"
\"
}
}
}

[/code:1]

La pièce jointe install_product.ps1 est absente ou indisponible

<br><br>Message édité par: Kinder, à: 1/03/10 15:28
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 14 ans 1 mois #6281 par Arnaud Petitjean
Réponse de Arnaud Petitjean sur le sujet Re:Install-product.ps1
Merci Kinder pour ton script !

MVP PowerShell et créateur de ce magnifique forum :-)
Auteur de 6 livres PowerShell aux éditions ENI
Fondateur de la société Start-Scripting
Besoin d'une formation PowerShell ?

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 14 ans 1 mois #6282 par Arnaud Petitjean
Réponse de Arnaud Petitjean sur le sujet Re:Install-product.ps1
Testé sous Windows 7, ça fonctionne :

[code:1]
PS &gt; C:\temp\install_product.ps1

Nom PSChildName Uninstall
---

7-Zip 4.65 7-Zip \&quot;C:\Program Files\7-Zip\Uninstall.exe\&quot;
Adobe AIR Adobe AIR C:\Program Files\Common Files\Adobe ...
Adobe Flash Player 10 ActiveX Adobe Flash Player ActiveX C:\Windows\system32\Macromed\Flash\u...
Adobe Flash Player 10 Plugin Adobe Flash Player Plugin C:\Windows\system32\Macromed\Flash\u...
Cities XL Cities XL D:\Program Files\Monte Cristo\Cities...
...[/code:1]<br><br>Message édité par: Arnaud, à: 1/03/10 23:22

MVP PowerShell et créateur de ce magnifique forum :-)
Auteur de 6 livres PowerShell aux éditions ENI
Fondateur de la société Start-Scripting
Besoin d'une formation PowerShell ?

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.076 secondes
Propulsé par Kunena