Solved

powershell script finding Windows 7 with/without service pack 1

Posted on 2014-10-24
4
288 Views
Last Modified: 2014-10-29
I am trying to find an easy way to determine which computers have a service pack 1 installed and those that don't.  This is in a domain.  I need to export the results to a text file in CSV format.

This is what I have so far.

$Catalog = GC "C:\Scripts\Windows7\list.txt"
ForEach($Machine in $Catalog)
{
If (Test-Connection $Machine -Count 1 -Quiet)
    {$Version = (wmic /node:$Machine os get Caption,CSDVersion /value)
            Write-Output "$Machine $Version" | Out-File "\\util02\support\Scripts\Reports\ComputerList-WindowsVersion-ServicePack.txt" -Append}
Else
    {
    Write-Output "$Machine is not available" | Out-File "\\util02\support\Scripts\Reports\ComputerList-WindowsVersion-ServicePack.txt" -Append}}    

I am getting output but for each computer in the network that it should pick up the info I am getting blank.
0
Comment
Question by:Keith Shackleton
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
Vaseem Mohammed earned 500 total points
ID: 40403261
we can get the required results using below code.
Assuming that you are running the script againest AD based computers.
The approach is different, but the code is easy to understand and many additional functions can be added in future.
In this code you get only computers that have "service pack 1"
The -Filter is used so that we don't get computer accounts that are running OS other than Windows.
As you are using text file as input, you can chance the code as it fits ur requirements.
$report=@()
$catalog = Get-ADComputer -Filter 'OperatingSystem -like "*Windows*"' | select Name
foreach($machine in $catalog){

if(Test-Connection $machine.Name -Count 1 -Quiet){
    $data = Get-WmiObject -Class win32_operatingsystem -ComputerName $machine.Name | where{$_.csdversion -eq "Service Pack 1"} | select CSName, Caption, CSDVersion
    $report += $data
    }
}
$report | Export-Csv -Path c:\OS_SP.csv -nti
$report

Open in new window

0
 
LVL 53

Expert Comment

by:McKnife
ID: 40403915
Why not use simple batch with ver.exe?
0
 

Author Comment

by:Keith Shackleton
ID: 40410884
Ok, I was able to find another script that does exactly (and more) than what I need.  Here it is.

Import-Module activedirectory

$ADComputerProperties = @(`
"Operatingsystem",
"OperatingSystemServicePack",
"Created",
"Enabled",
"LastLogonDate",
"IPv4Address",
"CanonicalName"
)
 
$SelectADComputerProperties = @(`
"Name",
"OperatingSystem",
"OperatingSystemServicePack",
"Created",
"Enabled",
"LastLogonDate",
"IPv4Address",
"CanonicalName"
)
 
Get-ADComputer -Filter * -Properties $ADComputerProperties  |  `
select $SelectADComputerProperties | Out-GridView
0
 

Author Closing Comment

by:Keith Shackleton
ID: 40410886
Although not exactly what I needed this answer is another way to get the info.  Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many admins will agree: WSUS is is a nice invention but using it on the client side when updating a newly installed computer is still time consuming as you have to do several reboots and furthermore, the procedure of installing updates, rebooting an…
This is a little timesaver I have been using for setting up Microsoft Small Business Server (SBS) in the simplest possible way. It may not be appropriate for every customer. However, when you get a situation where the person who owns the server is i…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now