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

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.

How to run GPResult on a remote client with PowerShell

In the past, to run the GPResult command, you would need to either physically visit this client, have the user do it, or use and RDP connection.  In all cases, this will disrupt the user.  First, you need PowerShell remoting enabled on the target machine.  You can do this via Group Policy . Open PowerShell and type this command. Invoke-Command –ScriptBlock {GPResult /r} –ComputerName <ComputerName> Replace <ComputerName> with the name of the target.  Remember, the target needs to be online and accessible to you.

Error icon when creating a GPO Preference drive map

You may not have an error at all.  Take a look at the drive mapping below. The red triangle is what threw us off.  It is not an error.  It is simply a color representation of the Replace option of the Action field in the properties of the drive mappings. Create action This give you a green triangle. The Create action creates a new mapped drive for users. Replace Action The Replace action gives you a red triangle.  This action will delete and recreate mapped drives for users. The net result of the Replace action is to overwrite all existing settings associated with the mapped drive. If the drive mapping does not exist, then the Replace action creates a new drive mapping. Update Action The Update action will have a yellow triangle. Update will modify settings of an existing mapped drive for users. This action differs from Replace in that it only updates settings defined within the preference item. All other settings remain as configured on the mapped drive. If the