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