Solved

powershell script finding Windows 7 with/without service pack 1

Posted on 2014-10-24
4
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 55

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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…
INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

630 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