Format the output in a log

Hi,

I just create a function to extract a list of all software updates and then output it ina CMTrace log.

The function look like this:

<pre class=“brush: powershell; gutter: true; first-line: 1; highlight: []; html-script: false”>

Function Get-MSHotfix
{
<#
#>

[CmdletBinding()]
param(

	[Parameter(Mandatory=$false)]
	[ValidateNotNullorEmpty()]
	[int16]$Jours

)

Begin {

	## Get the name of this function and write header
	[string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
	Set-StrictMode -off
		Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -CmdletBoundParameters $PSBoundParameters -Header
	Set-StrictMode -Version Latest

}## End Begin Script Block
Process {

	#https://social.technet.microsoft.com/Forums/windowsserver/en-US/4a6fb5be-04bf-492b-9ab1-d18906bdcd2f/wua-api?forum=winserverpowershell
	#http://www.pythian.com/blog/a-big-trick-listing-windows-updates-using-powershell/
	$Session = New-Object -ComObject &quot;Microsoft.Update.Session&quot;
	$Searcher = $Session.CreateUpdateSearcher()
	$historyCount = $Searcher.GetTotalHistoryCount()
	$MShotfix=$Session = New-Object -ComObject &quot;Microsoft.Update.Session&quot;
	$Searcher = $Session.CreateUpdateSearcher()
	$historyCount = $Searcher.GetTotalHistoryCount()
	$MShotfix=$Searcher.QueryHistory(0, $historyCount) | Select-Object @{name=&quot;Title&quot;; expression={[regex]::match($_.Title,’KB(\d+)’)}} , `
     Description, Date, SupportUrl , @{name=&quot;Operation&quot;; expression={switch($_.operation){ 1 {&quot;Installation&quot;}; 2 {&quot;Uninstallation&quot;}; 3 {&quot;Other&quot;}}}}`
	 | where { (Get-date($_.Date)) -gt (get-date).adddays(-$Jours) } `
 	 |Sort-Object -Property Date -descending |Format-Table
	
	
	&lt;#
	$MShotfix=Get-WmiObject -Class &quot;win32_quickfixengineering&quot; | Select-Object -Property &quot;HotfixID&quot;, &quot;Description&quot;, `
&quot;Caption&quot;, &quot;InstalledData&quot;, &quot;InstalledBy&quot;,`
 @{Name=&quot;InstalledOn&quot;; Expression={([DateTime]($_.InstalledOn)).ToLocalTime()}} | `
 where { (Get-date($_.Installedon)) -gt (get-date).adddays(-$Jours) } `
 |Sort-Object -Property InstalledOn -descending |Format-Table
	#&gt;
	
	Write-Output -InputObject $MShotfix

}## End Process

End {

Set-StrictMode -off
		Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -Footer
Set-StrictMode -Version Latest

}## End End

}## End Function Get-MSHotfix

Then I am calling the function:

<code>

$Var_MShotfix10j=Get-MSHotfix $Var_MShotfixdelai
[string]$StrVar_MShotfix=$Var_MShotfix | Out-String
Write-Log $StrVar_MShotfix -LogFilename $Var_Correctifs
</code>

At the end the output datas are not well fitting Under the title. Is it possible to get a good format in CMTRace?

Thanks,

Francois

I would like uploading the CMTrace log but I can’t find how. Any help would be appreciate. I don’t have access to cloud.

We currently write the log file using CMTrace compatible output, we also have a test-msupdates function which will detect if an update is installed on the target system. If you’re looking to get a list of msupdates while running the toolkit, you could adapt your function to use our write-log method.

We currently write the log file using CMTrace compatible output, we also have a test-msupdates function which will detect if an update is installed on the target system. If you’re looking to get a list of msupdates while running the toolkit, you could adapt your function to use our write-log method.