Original article address:Http://app.en25.com/e/es.aspx? S = 1403 & E = 4914 & elq = a3fdfdb4961d4feabec6e309570c5e33
Original article:
Powershell is great for parsing log files. here is a function that extracts all installed Windows updates from an internal log file and returns the information as pure powershell objects. have a look as this Code uses a number of powerful parsing and Wrapping Techniques:
Function get-Updates {
Get-content $ ENV: WinDir \ windowsupdate. Log -Encoding Utf8 |
Where-Object { $_ -Like '* Successfully installed *' } |
Foreach-Object {
$ Info = $ _. Split ( "'T" )
$ Hash = @{}
$ Hash . Installdate = [ Datetime ] $ Info [6]. Remove ( $ Info [6]. Lastindexof ( ":" ))
$ Hash . Product = $ Info [-1]. Split ( ":" )[ - 1]. Trim ()
New-Object Psobject -Property $ Hash
}
}
Get-Updates
Translation:
PowershellIt is very powerful in converting log files. The following functions extract all installedWindows updatesAnd use the informationPowershellObject display in a more pure way. BelowCodeSome very powerful conversion and packaging techniques are used:
Function get-Updates {
Get-content $ ENV: WinDir \ windowsupdate. Log -Encoding Utf8 |
Where-Object { $_ -Like '* Successfully installed *' } |
Foreach-Object {
$ Info = $ _. Split ( "'T" )
$ Hash = @{}
$ Hash . Installdate = [ Datetime ] $ Info [6]. Remove ( $ Info [6]. Lastindexof ( ":" ))
$ Hash . Product = $ Info [-1]. Split ( ":" )[ - 1]. Trim ()
New-Object Psobject -Property $ Hash
}
}
Get-Updates
Notes:
If you useGet-content $ ENV: WinDir \ windowsupdate. LogThe output information will be very messy.WhereAfter filtering and retrieving only some key columns and converting the data, it looks clearer.