Link to home
Start Free TrialLog in
Avatar of Keith Shackleton
Keith Shackleton

asked on

powershell script finding Windows 7 with/without service pack 1

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.
ASKER CERTIFIED SOLUTION
Avatar of Wasim Shaikh
Wasim Shaikh
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why not use simple batch with ver.exe?
Avatar of Keith Shackleton
Keith Shackleton

ASKER

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
Although not exactly what I needed this answer is another way to get the info.  Thanks.