Windows Version Report

This script was designed to search your domain and give an accurate breakdown of the number of Windows 7, 8, and 10 machines in your domain. The script also breaks down the different versions of Windows 10.
The script can match specific naming patterns, search a specific organization unit, and search a specific OS version. If you would like to export your findings, the script also includes the ability to export to CSV.


Search by Name

The $Like_Name variable allows you to narrow the search by only reporting on computers that contain a specific variable. 

The astrisk indicates a wildcard value. For example, if we have five computers named RM1001A, RM100B, RM100C, RM101A, and RM102B and the  $Like_Name value is set to  "RM*", the results would report all five computers. If the value is set to "*100*" only the computers in RM100 would be reported. If we set the value as "*C" only the computers ending in C would be reported.  


$Like_Name = "*"

Search by Organizational Unit

The $SearchBase value tells the script which organization unit to search. At a minimum, the distinguished name parent entry needs to be set as the $SearchBase value.


$SearchBase = "DC=localdomain,DC=net"

 CSV Export

The $Export_CSV value needs to be set only if you would like to export the results of the report to a CSV file. If you do not wish to export a CSV file you can leave the $Export_CSV value as two quotation marks ( "" ).


$Export_CSV = "C:\Users\username\Desktop\FileName.csv"

 Search by Operating System

We can select which operating systems we would like to report. To enable reporting on an operating system make the value equal to 1. If you would not like to report on an operating system make the value 0. 


# Enable search for Windows 7 Devices | Enable = 1 | Disable = 0

$Enable_WIN7 = 1

# Enable search for Windows 8 Devices | Enable = 1 | Disable = 0

$Enable_WIN8 = 1

# Enable search for Windows 10 Devices | Enable = 1 | Disable = 0

$Enable_WIN10 = 1

 Entire Script

This script is also available on Microsoft TechNet: http://bit.ly/2XaYZdW


###################################################
# ITLUMBERJACK.COM
# UPDATED ON: 6/12/19
# LICENSE: https://www.itlumberjack.com/mit-license
####################################################


# Like_Name : Enter characters you would like your results to display. 
# If do not want to filter an asterisk will need to be between the quotations. 

$Like_Name = "*"

# SearchBase : The organizational units you would like to search. 

$SearchBase = "DC=localdomain,DC=net"

# Export_CSV : File location of the CSV export. 
# If you do not want to export a CSV file, leave only the two quotations.
# Please note that if a CSV file with the same name already exists, the script will append information to the existing file. 
# To prevent duplicate information, be sure to make the CSV file different from an existing file. 

$Export_CSV = "C:\Users\username\Desktop\FileName.csv"

# Enable search for Windows 7 Devices | Enable = 1 | Disable = 0

$Enable_WIN7 = 1

# Enable search for Windows 8 Devices | Enable = 1 | Disable = 0

$Enable_WIN8 = 1

# Enable search for Windows 10 Devices | Enable = 1 | Disable = 0

$Enable_WIN10 = 1

#####################################################
### Start of Script : DO NOT EDIT PAST THIS POINT ###
#####################################################

$Computer_Names = Get-ADComputer -Filter {Name -like $Like_Name} -SearchBase $SearchBase | Select-Object Name

$1903 = 0
$1809 = 0
$1803 = 0
$1709 = 0
$1703 = 0
$1607 = 0 
$1511 = 0
$1507 - 0
$WIN8 = 0
$WIN7 = 0

foreach ($Computer_Name in $Computer_Names) {

    $Computer_Info = get-adcomputer $Computer_Name.Name -properties Name,OperatingSystem,OperatingSystemVersion,LastLogonDate,whenCreated

    #Windows 10

    If ($Computer_Info.OperatingSystem -like "*Windows 10*" -and $Enable_WIN10) {
    
        if ($Computer_Info.OperatingSystemVersion -like "*18362*" ) {Write-Host $Computer_Info.Name "|" $Computer_Info.OperatingSystem ": 1903"
        $1903++}
        if ($Computer_Info.OperatingSystemVersion -like "*17763*" ) {Write-Host $Computer_Info.Name "|" $Computer_Info.OperatingSystem ": 1809"
        $1809++}
        if ($Computer_Info.OperatingSystemVersion -like "*17134*" ) {Write-Host $Computer_Info.Name "|" $Computer_Info.OperatingSystem ": 1803"
        $1803++}
        if ($Computer_Info.OperatingSystemVersion -like "*16299*" ) {Write-Host $Computer_Info.Name "|" $Computer_Info.OperatingSystem ": 1709"
        $1709++}
        if ($Computer_Info.OperatingSystemVersion -like "*15063*" ) {Write-Host $Computer_Info.Name "|" $Computer_Info.OperatingSystem ": 1703"
        $1703++}
        if ($Computer_Info.OperatingSystemVersion -like "*14393*" ) {Write-Host $Computer_Info.Name "|" $Computer_Info.OperatingSystem ": 1607"
        $1607++}
        if ($Computer_Info.OperatingSystemVersion -like "*10586*" ) {Write-Host $Computer_Info.Name "|" $Computer_Info.OperatingSystem ": 1511"
        $1511++}
        if ($Computer_Info.OperatingSystemVersion -like "*10240*" ) {Write-Host $Computer_Info.Name "|" $Computer_Info.OperatingSystem ": 1507"
        $1507++}

    if ($Export_CSV) {$Computer_Info | Select-Object Name,DistinguishedName,OperatingSystem,OperatingSystemVersion,LastLogonDate,whenCreated,Enabled | Export-Csv $Export_CSV -Append}

    }

    #Windows 8 and 8.1

    if ($Computer_Info.OperatingSystem -like "*Windows 8*" -and $Enable_WIN8) {Write-Host $Computer_Info.Name "|" $Computer_Info.OperatingSystem
    $WIN8++

    if ($Export_CSV) {$Computer_Info | Select-Object Name,DistinguishedName,OperatingSystem,OperatingSystemVersion,LastLogonDate,whenCreated,Enabled | Export-Csv $Export_CSV -Append}

    }

    #Windows 7

    if ($Computer_Info.OperatingSystem -like "*Windows 7*" -and $Enable_WIN7) {Write-Host $Computer_Info.Name "|" $Computer_Info.OperatingSystem
    $WIN7++

    if ($Export_CSV) {$Computer_Info | Select-Object Name,DistinguishedName,OperatingSystem,OperatingSystemVersion,LastLogonDate,whenCreated,Enabled | Export-Csv $Export_CSV -Append}

    }

}

#Workstations

$Total_Workstations = $1903 + $1809 + $1803 + $1709 + $1703 + $1607 + $1511 + $1507 + $WIN8 + $WIN7

Write-Host ---------------------------------------------------
Write-Host "Workstations | Total Count:" $Total_Workstations
Write-Host ---------------------------------------------------

if ($Enable_WIN10) {

Write-Host "Windows 10 : Build Number 1903:" ($1903/$Total_Workstations).tostring("P") "| Total Count:" $1903 -ForegroundColor Green
Write-Host "Windows 10 : Build Number 1809:" ($1809/$Total_Workstations).tostring("P") "| Total Count:" $1809 -ForegroundColor Green
Write-Host "Windows 10 : Build Number 1803:" ($1803/$Total_Workstations).tostring("P") "| Total Count:" $1803 -ForegroundColor Green
Write-Host "Windows 10 : Build Number 1709:" ($1709/$Total_Workstations).tostring("P") "| Total Count:" $1709 -ForegroundColor Yellow
Write-Host "Windows 10 : Build Number 1703:" ($1703/$Total_Workstations).tostring("P") "| Total Count:" $1703 -ForegroundColor Yellow
Write-Host "Windows 10 : Build Number 1607:" ($1607/$Total_Workstations).tostring("P") "| Total Count:" $1607 -ForegroundColor Red
Write-Host "Windows 10 : Build Number 1511:" ($1511/$Total_Workstations).tostring("P") "| Total Count:" $1511 -ForegroundColor Red
Write-Host "Windows 10 : Build Number 1507:" ($1507/$Total_Workstations).tostring("P") "| Total Count:" $1507 -ForegroundColor Red

}

if ($Enable_WIN8) {Write-Host "Windows 8 and 8.1:" ($WIN8/$Total_Workstations).tostring("P")"| Total Count:" $WIN8 -ForegroundColor Yellow}

if($Enable_WIN7) {Write-Host "Windows 7:" ($WIN7/$Total_Workstations).tostring("P") "| Total Count:" $WIN7 -ForegroundColor Yellow}