Ajoy Rajan
asked on
Script to get Patch information for a particular KB
Hi,
I am trying to get a powershell script to get information from a list of servers about a particular KB installed.
I want to export the information to a CSV format.
Regards,
Ajoy
I am trying to get a powershell script to get information from a list of servers about a particular KB installed.
I want to export the information to a CSV format.
Regards,
Ajoy
ASKER
Hi oBdA,
I tried the script, I am getting the error:
Exception setting "Exception": "The property 'Exception' cannot be found on this object. Verify that the
property exists and can be set."
At C:\Temp\KB499175-Patchlook up-Final.p s1:22 char:4
+ $out.Exception = $exception
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationExceptio n
+ FullyQualifiedErrorId : ExceptionWhenSetting
Sorry I am basic with powershell.
I tried the script, I am getting the error:
Exception setting "Exception": "The property 'Exception' cannot be found on this object. Verify that the
property exists and can be set."
At C:\Temp\KB499175-Patchlook
+ $out.Exception = $exception
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationExceptio
+ FullyQualifiedErrorId : ExceptionWhenSetting
Sorry I am basic with powershell.
Try this Powershell script to query a particular patch is installed on remote computers
https://gallery.technet.microsoft.com/scriptcenter/Powershell-Query-a-patch-67cf35f8
https://gallery.technet.microsoft.com/scriptcenter/Powershell-Query-a-patch-67cf35f8
The line number in your error doesn't match what I posted above.
Please download the script from the code box above again (use the "Select All" link below the box); save as Get-Hotfix.ps1 or Whatever.ps1.
Change only lines 1-3 according to your settings.
Then just run as .\Get-Hotfix.ps1 from a PS console.
Please download the script from the code box above again (use the "Select All" link below the box); save as Get-Hotfix.ps1 or Whatever.ps1.
Change only lines 1-3 according to your settings.
Then just run as .\Get-Hotfix.ps1 from a PS console.
ASKER
I have tried this, the problem is that I want to run this from a server which has access to all other servers and do not have excel installed. This script needs excel application. This scripts calls out the excel application.
Note: if you only have a small list of servers, or for testing, you can define the server names directly in the script instead of using an input file; just set $computerList to a list of names instead of "Get-Content ..."
$computerList = 'Server1', 'Server2', 'Server3'
ASKER
Hi oBdA,
The list is quite big. Servers are nearly 100-175.
The list is quite big. Servers are nearly 100-175.
That's why I said "or for testing" ;)
For a first test, you can set the list to one server where you know the patch to be installed, one server where you know the patch to be not installed, and one server that does not exist.
For a first test, you can set the list to one server where you know the patch to be installed, one server where you know the patch to be not installed, and one server that does not exist.
$OutputFileLocation = "C:\temp\Logs-$(get-date -uformat '%Y-%m-%d-%H_%M').log"
###InputLocation
$Computers = Get-Content "c:\temp\computers.txt"
# Enter KB to be checked here
$Patch = Read-Host 'Enter the KB number? '
foreach ($Computer in $Computers)
{
$OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer
$sheetS = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Computer
$sheetPU = Get-WmiObject -Class Win32_Processor -ComputerName $Computer
$drives = Get-WmiObject -ComputerName $Computer Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3}
$pingStatus = Get-WmiObject -Query "Select * from win32_PingStatus where Address='$Computer'"
$OSRunning = $OS.caption + " " + $OS.OSArchitecture + " SP " + $OS.ServicePackMajorVersion
$systemType=$sheetS.SystemType
$date = Get-Date
$uptime = $OS.ConvertToDateTime($OS.lastbootuptime)
if
($kb=$(try {get-hotfix -id $Patch -ComputerName $computer} catch {$null}))
{
Write-Output "$patch is installed $Computer" | Out-File $OutputFileLocation -Append
}
else
{
Write-Output "$patch is not installed on $Computer" | Out-File $OutputFileLocation -Append
}
}
$erroractionpreference = “SilentlyContinue”
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The script works mate. Thanks for the help.
Open in new window