Forum Discussion
dmarquesgn
Sep 19, 2022Iron Contributor
Add column to an output
Hi, I'm creating a list of HotFixes installed, to control another script that deploys the patches. So I'm creating a command to check if an update has been installed on the last 10 days, plus if th...
- Sep 20, 2022
Hi,
For a single additional column, you can just cram it into the Select-Object as shown below.
If you were going to work with multiple new or existing columns, you'd probably branch out into a dedicated hash table.
Invoke-Command -ComputerName $server -ScriptBlock { # Get the last boot time. Getting it here up front once rather than many times within the loop is more efficient. $LastBootTime = (Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime; # Same principle for the cutoff date. No reason to have this in the loop. $CutoffDate = [datetime]::Today.AddDays(-10); # Loopy-da-loop time. Get-HotFix | Where-Object { $_.InstalledOn -gt $CutoffDate; } | Select-Object -Property @{name="LastBootUpTime"; expression={ $LastBootTime }}, CSName, Description, HotFixID, InstalledBy, InstalledOn; }
Which gives you:
Note that the real variable name for Source is CSName. You can re-brand that if you like back to Source using the same approach as for the new LastBootUpTime column but I haven't bothered doing so in this example.
Cheers,
Lain
Barrett70
Sep 20, 2022Copper Contributor
I'm especially stayed aware of the article and I will get many benefits from it. Subsequently, thank you for sharing it. DG Paystub Login