Skip to main content

Use PowerShell to test if a client can be upgraded to Windows 7

Here is one of  the scripts that I created for the 2011 scripting games.  It will test the local client to see if it can be upgraded to Windows 7.
Function Test-Win7Upgrade
{
<#
.SYNOPSIS
Test the local client to determine if the client can
be upgraded to Widows 7.
.DESCRIPTION
Test the local client to see if meets either the
requirements for the 32 bit or 64 bit version of
Windows 7.
.EXAMPLE
Test-Win7Upgrade
Returns the upgrade potential of the local client.
.NOTES
This function was originally developed for the 2011 scripting games. '
The WDDM test does take about 30 seconds to complete.
Please be patient.
Copyright 2011 MCTExpert, Inc.
Author: Jason Yoder
#>
    # Announce the start of the script.
    Write-Host "Testing for Windows 7 upgrade potential"
        
     
    # Create the array to hold the objects
    $CompData = @()
    # Create the object to hold this computer
    # currently being processed.
    $CompObj = New-Object PSObject
     
    # Add the Name Property
    $CompObj | Add-Member NoteProperty -name ComputerName -Value localhost
     
    # Get the Processor type
    # If the client is offline, enter a value of zero
    # and notify the user.
    Try {$CompObj | Add-Member NoteProperty -name Processor -Value (Get-WmiObject Win32_Processor -ErrorAction Stop).Architecture}
    Catch {
            $CompObj | Add-Member NoteProperty -name Processor -Value 99
            Write-Host "$Comp is not online"
          }
     
    # Get the processor speed.
    # If the client is offline, enter a value of zero.
    Try {$CompObj | Add-Member NoteProperty -name ClockSpeed -Value (Get-WmiObject Win32_Processor -ErrorAction Stop).CurrentClockSpeed}
    Catch {
            $CompObj | Add-Member NoteProperty -name ClockSpeed -Value 0
          }       
     
    # Get the RAM size
    Try {
        $Mem = Get-WmiObject Win32_PhysicalMemory -ErrorAction Stop
        ForEach ($M in $Mem){$Total += $m.Capacity}
        $CompObj | Add-Member NoteProperty -name RAM -Value ($Total/1GB)
        }
    Catch {
            $CompObj | Add-Member NoteProperty -name RAM -Value 0
         
     
    # Get the available hard drive space on drive C:
    Try {
        # Get the free space on the C: Drive.
        $HDGB = (Get-WmiObject Win32_LogicalDisk -Filter "DeviceID = 'C:'" -ErrorAction Stop).FreeSpace/1GB
         
        # Remove the decimal places from the free space.
        $HDGB = "{0:N0}" -f $HDGB
         
        # Add the free space property to $CompObj.
        $CompObj | Add-Member NoteProperty -name HDFree -Value $HDGB
        }
    Catch {
            $CompObj | Add-Member NoteProperty -name HDFree -Value 0
         
     
     
    # Before attempting to get the video drivers,
    # check to see the previous metrics are good
    # enough for Windows 7.  If not, do not even
    # bother.
     
     
    If  ((($CompObj.ClockSpeed -gt 900) -and
        ($CompObj.RAM -ge 1) -and
        ($CompObj.Processor -eq 0) -and
        ([int]$CompObj.HDFree -ge 16)) -or
        (($CompObj.ClockSpeed -gt 900) -and
        ($CompObj.RAM -ge 2) -and
        ($CompObj.Processor -eq 9) -and
        ([int]$CompObj.HDFree -ge 20)))
        {
         
        # Run the DXDIAG program and send the output to a
        # text file depending on the processor, an
        # extra switch for the 64bit systems.
         
        If ($CompObj.Processor -eq 0){DXDiag /t Dx.txt}
        If ($CompObj.Processor -eq 9){DXDiag /64bit /t Dx.txt}
         
        # Pause to allow DXDIAG time to start
        Start-Sleep -s 5
        $WaitingonDXDiag = $True
        Write-Host "Gathering Video Driver information from: $Comp"
        Write-Host "This will take a few seconds."
        Do {
            $Test = Get-Process | Where {$_.ProcessName -like "dxdiag*"}
            If ($Test -ne $null)
                {
                 Start-Sleep -s 1
                }
            If ($Test -eq $null) {$WaitingonDXDiag = $False}
            } While ($WaitingonDXDiag -eq $True)
         
         
        $DXData = Get-Content DX.txt
        $DXString = $DXData | Select-String -pattern "DirectX Version:"
        $WDDMString = $DXData | Select-String -pattern "Driver Model:"
        $DXString = (([string]$DXString) -replace "DirectX Version: DirectX", "").Trim()
        [int]$DXint32 = $DXString
        $WDDMString = (([string]$WDDMString) -replace "Driver Model: WDDM", "").Trim()
        [int]$WDDMint32 = $WDDMString
     
        $CompObj | Add-Member NoteProperty -name DXInfo -Value $DXint32
        $CompObj | Add-Member NoteProperty -name WDDMInfo -Value $WDDMint32
       
        # Delete the file created by DXDIAG.
        Remove-Item Dx.txt
         
        
               
        } # Close The Video Driver IF statement.
        Else {
            $CompObj | Add-Member NoteProperty -name DXInfo -Value 0
            $CompObj | Add-Member NoteProperty -name WDDMInfo -Value 0
            }
    
         
         
        # Determine if the client can be upgraded
        # to 64bit Windows 7.
        If (($CompObj.ClockSpeed -gt 900) -and
        ($CompObj.RAM -ge 2) -and
        ($CompObj.Processor -eq 9) -and
        ([int]$CompObj.HDFree -ge 20) -and
        ($CompObj.DXInfo -ge 9) -and
        ($CompObj.WDDMInfo -ge 1))
        {$CompObj | Add-Member NoteProperty -name Upgrade -Value "Windows 7 64 bit"}
         
        # Detemine if the client can be upgraded
        # to 32bit Windows 7.
        ElseIf (($CompObj.ClockSpeed -gt 900) -and
        ($CompObj.RAM -ge 1) -and
        ($CompObj.Processor -eq 0) -and
        ([int]$CompObj.HDFree -ge 16) -and
        ($CompObj.DXInfo -ge 9) -and
        ($CompObj.WDDMInfo -ge 1))
        {$CompObj | Add-Member NoteProperty -name Upgrade -Value "Windows 7 32 bit"}
     
        Else {$CompObj | Add-Member NoteProperty -name Upgrade -Value "Cannot be upgraded"}
     
    # Add the current object to the array
    $CompData += $CompObj
     
     
    #$CompData
    Write-Host "Test Completed."
}

Comments

Popular posts from this blog

Adding a Comment to a GPO with PowerShell

As I'm writing this article, I'm also writing a customization for a PowerShell course I'm teaching next week in Phoenix.  This customization deals with Group Policy and PowerShell.  For those of you who attend my classes may already know this, but I sit their and try to ask the questions to myself that others may ask as I present the material.  I finished up my customization a few hours ago and then I realized that I did not add in how to put a comment on a GPO.  This is a feature that many Group Policy Administrators may not be aware of. This past summer I attended a presentation at TechEd on Group Policy.  One organization in the crowd had over 5,000 Group Policies.  In an environment like that, the comment section can be priceless.  I always like to write in the comment section why I created the policy so I know its purpose next week after I've completed 50 other tasks and can't remember what I did 5 minutes ago. In the Group Policy module for PowerShell V3, th

Return duplicate values from a collection with PowerShell

If you have a collection of objects and you want to remove any duplicate items, it is fairly simple. # Create a collection with duplicate values $Set1 = 1 , 1 , 2 , 2 , 3 , 4 , 5 , 6 , 7 , 1 , 2   # Remove the duplicate values. $Set1 | Select-Object -Unique 1 2 3 4 5 6 7 What if you want only the duplicate values and nothing else? # Create a collection with duplicate values $Set1 = 1 , 1 , 2 , 2 , 3 , 4 , 5 , 6 , 7 , 1 , 2   #Create a second collection with duplicate values removed. $Set2 = $Set1 | Select-Object -Unique   # Return only the duplicate values. ( Compare-Object -ReferenceObject $Set2 -DifferenceObject $Set1 ) . InputObject | Select-Object – Unique 1 2 This works with objects as well as numbers.  The first command creates a collection with 2 duplicates of both 1 and 2.   The second command creates another collection with the duplicates filtered out.  The Compare-Object cmdlet will first find items that are diffe

How to list all the AD LDS instances on a server

AD LDS allows you to provide directory services to applications that are free of the confines of Active Directory.  To list all the AD LDS instances on a server, follow this procedure: Log into the server in question Open a command prompt. Type dsdbutil and press Enter Type List Instances and press Enter . You will receive a list of the instance name, both the LDAP and SSL port numbers, the location of the database, and its status.