Bonjour a tous,

je souhaites effectuer un reporting sur mon parc via la lecture d'une liste de postes dans une fichier .txt de deux clés de registre puis exporter le résultat dans un csv.

Cela fonctionne bien pour 1 clé (1 application). Mais je coince pour lire une seconde clé. tout ceci dans un array si possible.

J'ai déjà ce script fonctionnel :

Code Powershell : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
$computers = get-content "C:\Scripts\Get-InstalledApplications\pdt_gtal.txt"
$i = 0
$total = $computers.Count
 
$propertynames = 'DisplayName','DisplayVersion'  # you may use wildcards here
 
# loop over the computers
$result = foreach ($computer in $computers) {
$i++
            Write-Host "Connexion au $computer..." -ForegroundColor Yellow
            Write-Host "Checking $comp" -ForegroundColor Green
            Write-Host "$i sur $total verifiés."     -ForegroundColor Green
 
 
    if (!(Test-Connection -ComputerName $computer -Count 1 -Quiet)) {
        Write-Warning "Poste '$computer' non joignable"
        $hash = "null"
        continue   # skip this computer and proceed with the next
    }
    Invoke-Command -ComputerName $computer -ScriptBlock {
        $regPath_o365 = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\O365ProPlusRetail - fr-fr'
        $regPath_o13 = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Office15.STANDARD'
        # create a temporary Hashtable to store the items
        $hash = [ordered]@{}
        # loop over the properties
        foreach ($prop in $using:propertynames) {
            $entry = Get-ItemProperty -Path $regPath_o365 -Name $prop -ErrorAction SilentlyContinue
            $entry2 = Get-ItemProperty -Path $regPath_o13 -Name $prop -ErrorAction SilentlyContinue
            if ($entry) {
 
                $hash['ComputerName'] = $using:computer
                $entry = $entry | Select-Object * -ExcludeProperty PS*
 
                foreach ($item in $entry.PsObject.Properties) {
                    $hash[$item.Name] = $item.Value
 
                    Write-Host "Office 365 Detecté" -ForegroundColor White
 
                }
          } elseif($entry2) {
 
                $hash['ComputerName'] = $using:computer
                $entry2 = $entry2 | Select-Object * -ExcludeProperty PS*
 
                foreach ($item in $entry.PsObject.Properties) {
                    $hash[$item.Name] = $item.Value
 
                    Write-Host "Office 2013 Detecté" -ForegroundColor White
 
            }
            else {
                Write-Warning "Propriete non trouvee : '$prop'"
            }
        }
        if ($hash.Count) {
            # output the hash converted to PSObject
            [PsCustomObject]$hash
        }
    }
  }
}
# remove the properties added by Invoke-Command
$result = $result | Select-Object * -ExcludeProperty PS*,RunspaceId
 
# output to gridview
$result | Out-GridView
 
 
# output to CSV file
$result | Export-Csv -Path "C:\Scripts\Get-InstalledApplications\export_get_installedApps2.csv" -NoTypeInformation -Append

Nous pouvons voir les deux entrées de registre qui concerne O365 et Office 2013, je souhaite interroger les postes pour qu'il renvoit la valeur situé dans la clé s'il la trouve.

Peut-être changer de mode de recherche et dans le CSV mettre en colonne "Computer","O365","Office 2013" et mettre des "true" or "false".. ?
Exemple :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
ComputerName	O365	Office 2013
Computer1	True	False
Computer2	True	True
Computer3	False	True
Avez vous des conseils pour améliorer mon script ?

Merci