Answered by:
How to merge output of get hotfix details with system up-time?

Question
-
Is there any possibilities to merge output of get hotfix with system up-time?
Below command im using to get multiple server hotfix details, i just want to server up time in the output list.
get-content .\computers.txt | Where {$_ -AND (Test-Connection $_ -Quiet)} | foreach { Get-Hotfix -computername $_ | ft CSName,Description,HotFixID,InstalledBy,InstalledOn }
Tuesday, February 13, 2018 12:47 PM
Answers
-
How about this?
Get-Content .\computers.txt |Where {$_ -AND (Test-Connection $_ -Quiet)} |ForEach {$lastboot=Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $_ |Select -Expand LastBootUpTimeGet-Hotfix -ComputerName $_ |Select CSName,Description,HotFixID,InstalledBy,InstalledOn,
@{n='LastBootUpTime';e={$lastboot}}
}
- Edited by JS2010 Tuesday, February 13, 2018 10:37 PM
- Marked as answer by Partha1012 Wednesday, February 14, 2018 5:59 AM
Tuesday, February 13, 2018 8:20 PM
All replies
-
Hi,
Try this:
(Get-Hotfix -computername $_ | ft CSName,Description,HotFixID,InstalledBy,InstalledOn|out-string)+(invoke-command -computername $_{Get-CimInstance -ClassName win32_operatingsystem | select lastbootuptime|out-string})
Regards
Simon
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. Regards Simon Disclaimer: This posting is provided AS IS with no warranties or guarantees, and confers no rights.
- Edited by Simon.Rech Tuesday, February 13, 2018 1:12 PM corrected code
Tuesday, February 13, 2018 1:08 PM -
Thanks Simon, But im getting below error and fyi both the commands are working when we are checking individual command. problem here for merging the output
Invoke-Command : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At line:1 char:215
+ ... -computername $_{Get-CimInstance -ClassName win32_operatingsystem | select last ...
+ ~~
+ CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand.And when i check with below command
get-content .\computers.txt | Where {$_ -AND (Test-Connection $_ -Quiet)} | foreach ({Get-Hotfix -computername $_ | ft CSName,Description,HotFixID,InstalledBy,InstalledOn|out-string})+({Get-CimInstance -ClassName win32_operatingsystem | select lastbootuptime|out-string})
ForEach-Object : Cannot bind parameter 'RemainingScripts'. Cannot convert the "+" value of type "System.String" to
type "System.Management.Automation.ScriptBlock".
At line:1 char:77
+ get-content .\computers.txt | Where {$_ -AND (Test-Connection $_ -Quiet)} | fore ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [ForEach-Object], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ForEachObjectCommand- Edited by Partha1012 Tuesday, February 13, 2018 1:49 PM
Tuesday, February 13, 2018 1:44 PM -
How about this?
Get-Content .\computers.txt |Where {$_ -AND (Test-Connection $_ -Quiet)} |ForEach {$lastboot=Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $_ |Select -Expand LastBootUpTimeGet-Hotfix -ComputerName $_ |Select CSName,Description,HotFixID,InstalledBy,InstalledOn,
@{n='LastBootUpTime';e={$lastboot}}
}
- Edited by JS2010 Tuesday, February 13, 2018 10:37 PM
- Marked as answer by Partha1012 Wednesday, February 14, 2018 5:59 AM
Tuesday, February 13, 2018 8:20 PM -
Hi,
I agree with JS2010. In addition, for system uptime, you can have a try with the following script. Hope it is helpful to you:
Get-Content -Path .\computers.txt | Where-Object {$_ -and (Test-Connection -ComputerName $_ -Quiet)} | ForEach-Object { $upTime = (Get-Date) - (Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $_).LastBootUpTime Get-HotFix -ComputerName $_ | Format-Table CSName, Description, HotFixID, InstalledBy, InstalledOn, @{Name = 'UpTime'; Expression = {$upTime}} -AutoSize }
If you need further help, please feel free to let us know.
Best Regards,
Albert
Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com- Edited by Albert LingMicrosoft contingent staff Wednesday, February 14, 2018 5:41 AM
Wednesday, February 14, 2018 5:39 AM -
It working.. Thanks JS2010Wednesday, February 14, 2018 5:59 AM