Solved

powershell script finding Windows 7 with/without service pack 1

Posted on 2014-10-24
4
269 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Hallo! I guess almost every Windows Administrator must have got stumped with this question "Where does WINDOWS store a users cached credentials? Every user who had once logged onto a Server/Desktop while it was connected to the domain could sti…
Many times while working on a computer regardless of any Operating System, lag and crashes seem to creep in, hindering your working speed. Sometimes, it can also cause your work to be lost unexpectedly and as a result, you are unable to meet your de…
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). …
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

708 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

13 Experts available now in Live!

Get 1:1 Help Now