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\Co mputerList -WindowsVe rsion-Serv icePack.tx t" -Append}
Else
{
Write-Output "$Machine is not available" | Out-File "\\util02\support\Scripts\ Reports\Co mputerList -WindowsVe rsion-Serv icePack.tx t" -Append}}
I am getting output but for each computer in the network that it should pick up the info I am getting blank.
This is what I have so far.
$Catalog = GC "C:\Scripts\Windows7\list.
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\
Else
{
Write-Output "$Machine is not available" | Out-File "\\util02\support\Scripts\
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why not use simple batch with ver.exe?
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",
"OperatingSystemServicePac k",
"Created",
"Enabled",
"LastLogonDate",
"IPv4Address",
"CanonicalName"
)
$SelectADComputerPropertie s = @(`
"Name",
"OperatingSystem",
"OperatingSystemServicePac k",
"Created",
"Enabled",
"LastLogonDate",
"IPv4Address",
"CanonicalName"
)
Get-ADComputer -Filter * -Properties $ADComputerProperties | `
select $SelectADComputerPropertie s | Out-GridView
Import-Module activedirectory
$ADComputerProperties = @(`
"Operatingsystem",
"OperatingSystemServicePac
"Created",
"Enabled",
"LastLogonDate",
"IPv4Address",
"CanonicalName"
)
$SelectADComputerPropertie
"Name",
"OperatingSystem",
"OperatingSystemServicePac
"Created",
"Enabled",
"LastLogonDate",
"IPv4Address",
"CanonicalName"
)
Get-ADComputer -Filter * -Properties $ADComputerProperties | `
select $SelectADComputerPropertie
ASKER
Although not exactly what I needed this answer is another way to get the info. Thanks.