PowerShell 进程无需导出文件即可再次导入

PowerShell process without the need of exporting a file just to import it agian

以下过程有效,但需要使用输出文件然后再次导入它。我确信必须有更好的方法来编写此过程而无需 export/import 步骤。

代码

Get-Content -Path 'C:\Temp\Patch_Summary.csv' | Select-Object -Skip 6 | Out-File 'C:\Temp\TempPatchFile.csv' -Force
$PatchFile = Import-Csv 'K:\_Users\Keith\Documents\AOS Patch Certification\TempPatchFile.csv' | Select-Object @{ expression = {$_.Details_Table0_Title}; label = 'Name' }, UniqueUpdateID

foreach ($Patch in $PatchFile) {
  switch -WildCard ($Patch.Name) {
    '*2012*' { $Patch | Add-Member -MemberType NoteProperty -Name 'OS' -Value '2012' }
    '*2016*' { $Patch | Add-Member -MemberType NoteProperty -Name 'OS' -Value '2016' }
    '*2019*' { $Patch | Add-Member -MemberType NoteProperty -Name 'OS' -Value '2019' }
    Default {}
  }
}

$PatchFile = $PatchFile | Sort-Object -Property OS, Name

Patch_Summary.csv

DescriptionLabelTextbox,DescriptionTextbox
Description,This report returns the software updates that are contained in a specific deployment.

Header_Table1_CollectionName,Header_Table1_Available,Header_Table1_Deadline,Textbox1,Details_Table1_CollectionName,Details_Table1_Available,Details_Table1_Deadline,DeploymentID
Collection Name,Available,Deadline,Deployment ID,.APOM_Patch_Certification,9/10/2020 5:58:00 AM,,{B7EE09E8-9DD8-4DE5-AC38-4555AD9610FA}

Header_Table0_Title,Header_Table0_BulletinID,Header_Table0_ArticleID,Header_Table0_Present,Header_Table0_Missing,Header_Table0_NotApplicable,Header_Table0_Unknown,Header_Table0_Failed,Header_Table0_Pending,Textbox3,Details_Table0_Title,Details_Table0_BulletinID,Details_Table0_ArticleID,Details_Table0_Present,Details_Table0_Missing,Details_Table0_NotApplicable,Details_Table0_Unknown,Details_Table0_Failed,Details_Table0_Pending,UniqueUpdateID
Title,Bulletin ID,Article ID,Installed,Required,Not Required,Unknown,Failed,Pending,Update ID,"2020-07 Cumulative Update for .NET Framework 3.5, 4.7.2 and 4.8 for Windows Server 2019 for x64 (KB4566516)",,4566516,0,0,5,0,0,0,0d506775-e391-41bd-b932-d79df9147c9b
Title,Bulletin ID,Article ID,Installed,Required,Not Required,Unknown,Failed,Pending,Update ID,2020-08 Cumulative Security Update for Internet Explorer 11 for Windows Server 2012 R2 for x64-based systems (KB4571687),,4571687,1,1,3,0,0,0,0f07444e-6221-4077-b693-9d8e7d64e872
Title,Bulletin ID,Article ID,Installed,Required,Not Required,Unknown,Failed,Pending,Update ID,"2020-08 Cumulative Update for .NET Framework 3.5, 4.7.2 and 4.8 for Windows Server 2019 for x64 (KB4570505)",,4570505,1,0,4,0,0,0,35e0f439-aec4-4398-879b-7866e0a8eb62
Title,Bulletin ID,Article ID,Installed,Required,Not Required,Unknown,Failed,Pending,Update ID,2020-08 Cumulative Update for .NET Framework 4.8 for Windows Server 2016 (1803) for x64 (KB4569749),,4569749,0,0,5,0,0,0,d95875ba-af5b-441c-ba93-8c111f49ba71
Title,Bulletin ID,Article ID,Installed,Required,Not Required,Unknown,Failed,Pending,Update ID,2020-08 Cumulative Update for .NET Framework 4.8 for Windows Server 2016 for x64 (KB4569746),,4569746,1,0,4,0,0,0,b3d9d297-418f-46e3-86cc-ed6362eb154b
Title,Bulletin ID,Article ID,Installed,Required,Not Required,Unknown,Failed,Pending,Update ID,2020-08 Cumulative Update for Windows Server 2016 for x64-based Systems (KB4571694),,4571694,1,1,3,0,0,0,cf7a53b4-c18c-4c38-b4ef-711043f4d178
Title,Bulletin ID,Article ID,Installed,Required,Not Required,Unknown,Failed,Pending,Update ID,2020-08 Cumulative Update for Windows Server 2019 for x64-based Systems (KB4565349),,4565349,1,0,4,0,0,0,1e857e5a-9432-4eaa-8c29-a755cc55f91d
Title,Bulletin ID,Article ID,Installed,Required,Not Required,Unknown,Failed,Pending,Update ID,"2020-08 Security and Quality Rollup for .NET Framework 3.5, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 for Windows 8.1 and Server 2012 R2 for x64 (KB4570508)",,4570508,0,2,3,0,0,1,0b02eea9-9517-4f0f-adb4-1381bde7a3d4
Title,Bulletin ID,Article ID,Installed,Required,Not Required,Unknown,Failed,Pending,Update ID,2020-08 Security Monthly Quality Rollup for Windows Server 2012 R2 for x64-based Systems (KB4571703),,4571703,1,1,3,0,0,0,41841c9a-956c-4b83-a626-58a1848f515b
Title,Bulletin ID,Article ID,Installed,Required,Not Required,Unknown,Failed,Pending,Update ID,2020-08 Security Only Quality Update for Windows Server 2012 R2 for x64-based Systems (KB4571723),,4571723,1,1,3,0,0,0,218e6900-fb95-4be6-be8d-a246fbf73ad7
Title,Bulletin ID,Article ID,Installed,Required,Not Required,Unknown,Failed,Pending,Update ID,"2020-08 Security Only Update for .NET Framework 3.5, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 for Windows 8.1 and Server 2012 R2 for x64 (KB4570502)",,4570502,0,2,3,0,0,1,c72fc911-8cbc-4a9a-bd12-073b2b7ec0bb   
Title,Bulletin ID,Article ID,Installed,Required,Not Required,Unknown,Failed,Pending,Update ID,2020-08 Servicing Stack Update for Windows Server 2019 for x64-based Systems (KB4566424),,4566424,1,0,4,0,0,0,47056470-c0fd-466f-845b-66f418c46420

期望的结果

Name                                                                                                                                                                UniqueUpdateID                       OS
----                                                                                                                                                                --------------                       --
2020-08 Cumulative Security Update for Internet Explorer 11 for Windows Server 2012 R2 for x64-based systems (KB4571687)                                            0f07444e-6221-4077-b693-9d8e7d64e872 2012
2020-08 Security and Quality Rollup for .NET Framework 3.5, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 for Windows 8.1 and Server 2012 R2 for x64 (KB4570508) 0b02eea9-9517-4f0f-adb4-1381bde7a3d4 2012
2020-08 Security Monthly Quality Rollup for Windows Server 2012 R2 for x64-based Systems (KB4571703)                                                                41841c9a-956c-4b83-a626-58a1848f515b 2012
2020-08 Security Only Quality Update for Windows Server 2012 R2 for x64-based Systems (KB4571723)                                                                   218e6900-fb95-4be6-be8d-a246fbf73ad7 2012
2020-08 Security Only Update for .NET Framework 3.5, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 for Windows 8.1 and Server 2012 R2 for x64 (KB4570502)        c72fc911-8cbc-4a9a-bd12-073b2b7ec0bb 2012
2020-08 Cumulative Update for .NET Framework 4.8 for Windows Server 2016 (1803) for x64 (KB4569749)                                                                 d95875ba-af5b-441c-ba93-8c111f49ba71 2016
2020-08 Cumulative Update for .NET Framework 4.8 for Windows Server 2016 for x64 (KB4569746)                                                                        b3d9d297-418f-46e3-86cc-ed6362eb154b 2016
2020-08 Cumulative Update for Windows Server 2016 for x64-based Systems (KB4571694)                                                                                 cf7a53b4-c18c-4c38-b4ef-711043f4d178 2016
2020-07 Cumulative Update for .NET Framework 3.5, 4.7.2 and 4.8 for Windows Server 2019 for x64 (KB4566516)                                                         0d506775-e391-41bd-b932-d79df9147c9b 2019
2020-08 Cumulative Update for .NET Framework 3.5, 4.7.2 and 4.8 for Windows Server 2019 for x64 (KB4570505)                                                         35e0f439-aec4-4398-879b-7866e0a8eb62 2019
2020-08 Cumulative Update for Windows Server 2019 for x64-based Systems (KB4565349)                                                                                 1e857e5a-9432-4eaa-8c29-a755cc55f91d 2019
2020-08 Servicing Stack Update for Windows Server 2019 for x64-based Systems (KB4566424)                                                                            47056470-c0fd-466f-845b-66f418c46420 2019
$PatchFile = Get-Content -Path 'C:\Temp\Patch_Summary.csv' | Select-Object -Skip 6 | ConvertFrom-Csv | Select-Object @{ expression = {$_.Details_Table0_Title}; label = 'Name' }, UniqueUpdateID