Solved

powershell script finding Windows 7 with/without service pack 1

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

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Log files are useful in diagnosing and repairing problems.  This is a list of common log files and their standard locations that I've compiled.   While this is not exhaustive, it is a pretty good list that I've found to be useful.  I may update it f…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
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). …

809 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