Custom cloum creation

prabhat kumar 1 Reputation point
2020-08-12T12:04:39.537+00:00

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
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,455 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 45,831 Reputation points
    2020-08-12T15:07:39.177+00:00

    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++
                }
            }
    
    1 person found this answer helpful.
    0 comments No comments

  2. 2020-08-20T01:51:16.16+00:00

    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.
    :)

    0 comments No comments