I am trying to get all the list of KB installed on multiple servers and get the last reboot time of the system. My requirement is to get the result in csv or text format with column name “Hostname” , “KB Name” , “installed by” , “installed on” and “Last reboot”. I have to execute 2 script to get this done and then i have to format it and i dont want other columns which i am receiving from code 1 only limited column are required.. Can some please help me to get the same format which i reuired?
Output required in below format :
"Source" "Description" "HotFixID" "InstalledBy" "InstalledOn" "Last Reboot"
Please find below 2 code.
FYI : I am new to powershell.
Code 1: This will list all KB installed patch.
$computers = Get-Content -path "C:UsersjoyDesktopMachine_List.txt"
$patches = Get-Content -path "C:UsersjoyDesktopKB_List.txt"
foreach ($computer in $computers){
foreach ($patch in $patches){
Get-HotFix -id $patch -ComputerName $computer | -OutVariable results -ErrorAction SilentlyContinue
if ($results -ne $null) {
$results | Out-File C:UsersjoyDesktopreport1.txt -Append -Force
}
else {
Add-content "$Patch is not Present in $computer" -path "C:UsersjoyDesktopreport2.txt"
}
}
Code 2: This will get the last reboot of the system.
$machines = Get-Content C:UsersjoyDesktopMachine_List.txt
$report = @()
$object = @()
foreach($machine in $machines)
{
$machine
$object = gwmi win32_operatingsystem -ComputerName $machine | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
$report += $object
}
$report | Export-csv C:UsersjoyDesktopReboot.csv
One Comment
Dharani
Try this, This will allow you to get information what you are looking for. But this script only get installed patches information from the remote machines, If you want add one more loop to print the patches which are installed on another text file.