Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

powershell script finding Windows 7 with/without service pack 1

Posted on 2014-10-24
4
Medium Priority
?
416 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 2000 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 57

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction: I have always been a big fan of Windows but my liking towards it is slowly being eroded by the variety of other Applications that I encounter, when I browse the Web. Most of the software available is free and maybe Open Source too. …
This article describes how to set permissions to allow a limited-permissions user to start and stop a particular System Service.   It is always best to give users only the permissions that they need to perform their job, so tweaking particular permi…
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…

963 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