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 "Microsoft.Update.Session"
$Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$MShotfix=$Session = New-Object -ComObject "Microsoft.Update.Session"
$Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$MShotfix=$Searcher.QueryHistory(0, $historyCount) | Select-Object @{name="Title"; expression={[regex]::match($_.Title,’KB(\d+)’)}} , `
Description, Date, SupportUrl , @{name="Operation"; expression={switch($_.operation){ 1 {"Installation"}; 2 {"Uninstallation"}; 3 {"Other"}}}}`
| where { (Get-date($_.Date)) -gt (get-date).adddays(-$Jours) } `
|Sort-Object -Property Date -descending |Format-Table
<#
$MShotfix=Get-WmiObject -Class "win32_quickfixengineering" | Select-Object -Property "HotfixID", "Description", `
"Caption", "InstalledData", "InstalledBy",`
@{Name="InstalledOn"; Expression={([DateTime]($_.InstalledOn)).ToLocalTime()}} | `
where { (Get-date($_.Installedon)) -gt (get-date).adddays(-$Jours) } `
|Sort-Object -Property InstalledOn -descending |Format-Table
#>
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