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.

Where did a User’s Account Get Locked Out?

Updated: May 15, 2015 When this article was originally published, two extra carriage returns were add causing the code to malfunction.  The code below is correct.   My client for this week’s PowerShell class had a really interesting question. They needed to know where an account is being locked out at. OK, interesting. Apparently users hop around clients and forget to log off, leading to eventual lock out of their accounts. The accounts can be unlocked, but are then relocked after Active Directory replication. This problem is solved in two parts. The first one is to modify the event auditing on the network. The second part is resolved with PowerShell. The first part involves creating a group policy that will encompass your Domain Controllers. In this GPO, make these changes. Expand Computer Configuration \ Policies \ Windows Settings \ Security Settings \ Advanced Audit Policy Configuration \ Audit Policies \ Account Management Double click User Account Management C...