Nouvelle catégorie : Technet. Je vais déposer des scripts sympas trouver sur le site de Microsoft. Celui-ci je l’ai simplifié et rendu fonctionnel :
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 72 73 74 75 76 77 78 79 80 81 |
function Get-ProductKey { <# .SYNOPSIS Information clef produit et système d'exploitation. .DESCRIPTION A l'aide des commandes WmiObject récupération des informations de windows et de la licence. .PARAMETER Computername Nom du pc local ou du pc distant. .NOTES Author: Boe Prox modification Naylo :) Version: 1.0 .EXAMPLE Get-ProductKey -Computername Server1 OSDescription Computername OSVersion ProductKey ------------- ------------ --------- ---------- Microsoft(R) Windows(R) Server 2003, Enterprise Edition Server1 5.2.3790 bcdfg-hjklm-pqrtt-vwxyy-12345 Description ----------- Clef d'activation de 'Server1' #> [cmdletbinding()] Param ( [parameter(ValueFromPipeLine=$True,ValueFromPipeLineByPropertyName=$True)] [Alias("CN","__Server","IPAddress","Server")] [string[]]$Computername = $Env:Computername ) Begin { $map="BCDFGHJKMPQRTVWXY2346789" } Process { ForEach ($Computer in $Computername) { Write-Verbose ("{0}: Test de la connectivité" -f $Computer) If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) { Try { Write-Verbose ("{0}: Informations OS" -f $Computer) $OS = Get-WmiObject -ComputerName $Computer Win32_OperatingSystem -ErrorAction Stop } Catch { $OS = New-Object PSObject -Property @{ Caption = $_.Exception.Message Version = $_.Exception.Message } } Try { $ProductKey = "" Write-Verbose ("{0}: Récupération de la clef produit" -f $Computer) $ProductKey = (Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey } Catch { $ProductKey = $_.Exception.Message } $object = New-Object PSObject -Property @{ Computername = $Computer ProductKey = $ProductKey OSDescription = $os.Caption OSVersion = $os.Version } $object.pstypenames.insert(0,'ProductKey.Info') $object } Else { $object = New-Object PSObject -Property @{ Computername = $Computer ProductKey = 'Unreachable' OSDescription = 'Unreachable' OSVersion = 'Unreachable' } $object.pstypenames.insert(0,'ProductKey.Info') $object } } } } #Get-ProductKey -Verbose |
On récupère donc OS et sa version et la fameuse clef produit. Vous pouvez également utiliser directement cette commande sur votre poste pour simplifier :
1 |
powershell "(Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey" |
Le petit plus…