I have written a script to export all the installed patches into a CSV file and I have added the server boot time variable for the to output, but my output is having a name with the boot time, I just need the date and time for the particular server but not the last bootup time word in the output
Output @{lastbootuptime=1/14/2022 4:44:54 AM}
<#
Script to list all installed MS Patches on a remote system and export
.DESCRIPTION
This Script is used to check for all installed MS Patchesres on the specified servers and to export.
#>
## Clear the PS Console
Clear-Host
## Remove the Existing Out file
$FileName = "C:\Users\a-lchandrakanthredd\Desktop\Test\Installed_Patches.csv"
if (Test-Path $FileName) {
Remove-Item $FileName
Write-Host "Deleted the Existing OutPut file" -BackgroundColor Red -ForegroundColor Green
}
## List of Servers to check for Installed Patches
$serversToCheck = Get-Content "C:\Users\a-lchandrakanthredd\Desktop\Test\Servers.txt"
## Define the Output file path
$outfile = "C:\Users\a-lchandrakanthredd\Desktop\Test\Installed_Patches.csv"
## Lopping through specified servers
ForEach ( $server in $serversToCheck )
{
##Server Boot Time
$BootTime = Get-CimInstance -ClassName win32_operatingsystem | select lastbootuptime
Get-WmiObject Win32_QuickFixEngineering -ComputerName $server |
Where-Object { $_.InstalledOn -gt (Get-Date).AddMonths(-3) } |
Select-Object -Property PSComputerName, __PATH, Description, InstalledOn, HotFixID, InstalledBy, @{n='Server_Boot_Time';e={$BootTime}} |
Export-Csv -Path $outfile -Append
}
CodePudding user response:
you just need to modify the the $BootTime variable to be:
$BootTime = (Get-CimInstance -ClassName win32_operatingsystem).lastbootuptime
OR
Get-CimInstance -ClassName win32_operatingsystem | select -ExpandProperty lastbootuptime
