


Comment obtenir le nombre d'ordinateurs par système d'exploitation Windows dans un domaine Active Directory en utilisant Powershell (FR) | |||||||||||||||||||||||||||||
Dans un domaine Active Directory, les détails sur la version d'un système d'exploitation sont stockés dans deux attributs sur les comptes d'ordinateurs :
![]()
Operating System Version: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx Si vous avez besoin d'obtenir le nombre d'ordinateurs par système d'exploitation Windows dans votre domaine Active Directory, vous pouvez effectuer cette opération en utilisant des requêtes LDAP sur votre Active Directory. Le script Powershell suivant permet la satisfaction de ce besoin : ----------------------------------------------------------------------------------------------------------------------------- cls $tableOSName="OperatingSystems" $tableOS=New-Objectsystem.Data.DataTable“$tableOSName” $colOS=New-Objectsystem.Data.DataColumnOperatingSystem,([string]) $colOSversion=New-Objectsystem.Data.DataColumnOperatingSystemVersion,([string]) $colOSType=New-Objectsystem.Data.DataColumnOperatingSystemType,([string]) $tableOS.columns.add($colOS) $tableOS.columns.add($colOSversion) $tableOS.columns.add($colOSType) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows 8.1" $rowtableOS.OperatingSystemVersion="6.3" $rowtableOS.OperatingSystemType="WorkStation" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows 8" $rowtableOS.OperatingSystemVersion="6.2" $rowtableOS.OperatingSystemType="WorkStation" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows 7" $rowtableOS.OperatingSystemVersion="6.1" $rowtableOS.OperatingSystemType="WorkStation" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows Vista" $rowtableOS.OperatingSystemType="WorkStation" $rowtableOS.OperatingSystemVersion="6.0" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows XP 64-Bit Edition" $rowtableOS.OperatingSystemVersion="5.2" $rowtableOS.OperatingSystemType="WorkStation" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows XP" $rowtableOS.OperatingSystemVersion="5.1" $rowtableOS.OperatingSystemType="WorkStation" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows 2000 Professional" $rowtableOS.OperatingSystemVersion="5.0" $rowtableOS.OperatingSystemType="WorkStation" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows Server 2012 R2" $rowtableOS.OperatingSystemVersion="6.3" $rowtableOS.OperatingSystemType="Server" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows Server 2012" $rowtableOS.OperatingSystemVersion="6.2" $rowtableOS.OperatingSystemType="Server" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows Server 2008 R2" $rowtableOS.OperatingSystemVersion="6.1" $rowtableOS.OperatingSystemType="Server" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows Server® 2008" $rowtableOS.OperatingSystemVersion="6.0" $rowtableOS.OperatingSystemType="Server" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows Server 2003" $rowtableOS.OperatingSystemVersion="5.2" $rowtableOS.OperatingSystemType="Server" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows 2000 Server" $rowtableOS.OperatingSystemVersion="5.0" $rowtableOS.OperatingSystemType="Server" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows 2000 Advanced Server" $rowtableOS.OperatingSystemVersion="5.0" $rowtableOS.OperatingSystemType="Server" $tableOS.Rows.Add($rowtableOS) $rowtableOS=$tableOS.NewRow() $rowtableOS.OperatingSystem="Windows 2000 Datacenter Server" $rowtableOS.OperatingSystemVersion="5.0" $rowtableOS.OperatingSystemType="Server" $tableOS.Rows.Add($rowtableOS) write-host"WorkStation Operating Systems : "-foregroundcolor"Green" $WorkStationCount=0 foreach($objectin($tableOS|where{$_.OperatingSystemType-eq'WorkStation'})) { $LDAPFilter="(&(operatingsystem="+$object.OperatingSystem+"*)(operatingsystemversion="+$object.OperatingSystemVersion+"*))" $OSCount=(Get-ADComputer-LDAPFilter$LDAPFilter).Count if($OSCount-ne$null) { ""+$object.OperatingSystem+": "+$OSCount+"" } else { ""+$object.OperatingSystem+": 0" $OSCount=0 } $WorkStationCount+=$OSCount } $WorkStationTotalNumber="Total Number : "+$WorkStationCount+"" write-host$WorkStationTotalNumber-foregroundcolor"Yellow" write-host"" write-host"Server Operating Systems : "-foregroundcolor"Green" $ServerCount=0 foreach($objectin($tableOS|where{$_.OperatingSystemType-eq'Server'})) { $LDAPFilter="(&(operatingsystem="+$object.OperatingSystem+"*)(operatingsystemversion="+$object.OperatingSystemVersion+"*))" $OSCount=(Get-ADComputer-LDAPFilter$LDAPFilter).Count if($OSCount-ne$null) { ""+$object.OperatingSystem+": "+$OSCount+"" } else { ""+$object.OperatingSystem+": 0" $OSCount=0 } $ServerCount+=$OSCount } $ServerTotalNumber="Total Number : "+$ServerCount+"" write-host$ServerTotalNumber-foregroundcolor"Yellow" write-host"" $LDAPFilter="(&(operatingsystem=*)" foreach($objectin$tableOS) { $LDAPFilter+="(!(&(operatingsystem="+$object.OperatingSystem+"*)(operatingsystemversion="+$object.OperatingSystemVersion+"*)))" } $LDAPFilter+=")" $OthersCount=(Get-ADComputer-LDAPFilter$LDAPFilter).Count $OthersTotalNumber="Total Number : "+$OthersCount+"" write-host"Other Operating Systems : "-foregroundcolor"Green" write-host$OthersTotalNumber-foregroundcolor"Yellow" ----------------------------------------------------------------------------------------------------------------------------- Lorsque vous exécutez ce script, vous aurez le nombre d'ordinateurs par système d'exploitation Windows affiché : ![]() Vous trouverez également le nombre d'ordinateurs pour "Other Operating Systems". Il s'agit principalement de :
Le script utilise une table qui comporte les colonnes suivantes :
![]()
Où $object.OperatingSystem est une variable qui contient la valeur du système d'exploitation sur la ligne et $object.OperatingSystemVersion est une variable qui contient la valeur de la Version du système d'exploitation de la ligne. Le filtre LDAP permet d'obtenir les comptes d'ordinateurs qui ont :
Quant à "Other Operating Systems", le script utilise le filtre LDAP suivant :
Autres langues Cet article est disponible dans d'autres langues. |
The latest tutorials
About Tunit
Tunit helps you plan your Microsoft systems integration and administration.
Certainly, having a good Management of your IT systems improve your Business performance while it can, when it is poorly managed, obstruct the responsiveness and efficiency of your organization. We are here to help you so do not hesitate to follow us.
View more