question

prabhatkumar-2410 avatar image
0 Votes"
prabhatkumar-2410 asked YoungYang-MSFT answered

Custom cloum creation


WSUSCL02-2012

Monday, August 10, 2020 5:03:08 PM



X Status KB Size Title


2 Accepted KB3172729 10 MB Security Update for Windows Server 2012 R2 (KB...
2 Accepted KB3175024 12 MB Security Update for Windows Server 2012 R2 (KB...
3 Downloaded KB3172729 10 MB Security Update for Windows Server 2012 R2 (KB...
3 Downloaded KB3175024 12 MB Security Update for Windows Server 2012 R2 (KB...
4 Installed KB3172729 10 MB Security Update for Windows Server 2012 R2 (KB...
4 Installed KB3175024 12 MB Security Update for Windows Server 2012 R2 (KB...



WSUSCL01-2012

Monday, August 10, 2020 5:03:01 PM



X Status KB Size Title


2 Accepted KB2962409 50 MB Update for Windows Server 2012 R2 (KB2962409)
2 Accepted KB3175024 12 MB Security Update for Windows Server 2012 R2 (KB...
3 Downloaded KB2962409 50 MB Update for Windows Server 2012 R2 (KB2962409)
3 Downloaded KB3175024 12 MB Security Update for Windows Server 2012 R2 (KB...
4 Installed KB2962409 50 MB Update for Windows Server 2012 R2 (KB2962409)
4 Installed KB3175024 12 MB Security Update for Windows Server 2012 R2 (KB...



Above is the data set on that i have to filter out server name, date, and installed patch details and put those data in custom powershell object with the name of (SERVERNAME,DATE,PATCH)

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
1 Vote"
RichMatheisen-8856 answered

Provided the format of the file doesn't change, this will work:

 $m = ($a = Get-Content C:\junk\patch.txt) |
     Select-String -Pattern "X Status KB Size Title" -SimpleMatch -AllMatches -Context 6,0 |
         ForEach-Object{
             $Server = $_.Context.PreContext[0]
             $Date   = [DateTime]$_.Context.PreContext[2]
             $PatchLineIndex = $_.LineNumber + 1
             While ( ($a[$PatchLineIndex].Trim().Length) -gt 40 -and $PatchLineIndex -lt ($a.length -1)){
                 [PSCustomObject]@{
                     Server = $Server
                     Date = $Date
                     Patch = ($a[$PatchLineIndex] -Split " ")[2]
                 }
                 $PatchLineIndex++
             }
         }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YoungYang-MSFT avatar image
0 Votes"
YoungYang-MSFT answered

Hi, given that this post has been quiet for a while, this is a quick question and answer. Has your question been solved? If so, please mark it as an answer so that users with the same question can find and get help.
:)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.