Copy right symbol not when i am extracting particular column

Hi Team,

I have a .csv file which contains the operating system and kb articles, I like to test the kb articles against when the Operating system matches. but the Operating system has a copyright symbol it is not coming when I extract only the operating system.

PS C:\Scripts> $patchesToVerify

Operating_System KB_Article


Microsoft Windows Server 2012 R2 Standard KB4530730
Microsoft Windows Server 2016 Standard KB4530689
Microsoft® Windows Server® 2008 Standard KB4530719
Microsoft Windows Server 2012 Standard KB4530698
Microsoft Windows Server 2008 R2 Standard KB4530692
Microsoft Windows Server 2016 Standard KB4532936
Microsoft Windows Server 2016 Standard KB4534293
Microsoft Windows Server 2016 Standard KB4532933
Microsoft® Windows Server® 2008 Standard KB4534312
Microsoft Windows Server 2012 R2 Standard KB4534978
Microsoft® Windows Server® 2008 Standard KB4534979
Microsoft Windows Server 2016 Standard KB4534271
Microsoft Windows Server 2008 R2 Standard KB4534314
Microsoft Windows Server 2012 Standard KB4354977
Microsoft Windows Server 2012 Standard KB4534288
Microsoft Windows Server 2012 R2 Standard KB4534309
Microsoft® Windows Server® 2008 Standard KB4534312
Microsoft Windows Server 2008 R2 Standard KB4534876
Microsoft® Windows Server® 2008 Standard KB4537822
Microsoft Windows Server 2016 Standard KB4537759
Microsoft Windows Server 2008 R2 Standard KB4537813
Microsoft Windows Server 2012 R2 Standard KB4537803
Microsoft Windows Server 2016 Standard KB4537764
Microsoft Windows Server 2012 Standard KB4537794
Microsoft Windows Server 2016 Standard KB4537762

 

PS C:\Scripts> $patchesToVerify.operating_system
Microsoft Windows Server 2012 R2 Standard
Microsoft Windows Server 2016 Standard
Microsoft� Windows Server� 2008 Standard
Microsoft Windows Server 2012 Standard
Microsoft Windows Server 2008 R2 Standard
Microsoft Windows Server 2016 Standard
Microsoft Windows Server 2016 Standard
Microsoft Windows Server 2016 Standard
Microsoft� Windows Server� 2008 Standard
Microsoft Windows Server 2012 R2 Standard
Microsoft� Windows Server� 2008 Standard
Microsoft Windows Server 2016 Standard
Microsoft Windows Server 2008 R2 Standard
Microsoft Windows Server 2012 Standard
Microsoft Windows Server 2012 Standard
Microsoft Windows Server 2012 R2 Standard
Microsoft� Windows Server� 2008 Standard
Microsoft Windows Server 2008 R2 Standard
Microsoft� Windows Server� 2008 Standard
Microsoft Windows Server 2016 Standard
Microsoft Windows Server 2008 R2 Standard
Microsoft Windows Server 2012 R2 Standard
Microsoft Windows Server 2016 Standard
Microsoft Windows Server 2012 Standard
Microsoft Windows Server 2016 Standard

$RS_W32OSCaption = @(Get-WmiObject win32_operatingsystem -ComputerName $computername | Select-Object caption).Caption

$KBs = ($patchesToVerify |Where-Object {$_.operating_system -eq $RS_W32OSCaption} | Select-Object KB_Article).kb_article

 

it is giving empty output.

 

Please help

 

Thanks,

Naveen

Please format your code as code using the code tag button labeled “PRE”. Thanks. When you post example data or console output you should format this as code as well please.

You should get rid of the servers with 2008 and 2008R2. Their support ended more than one month ago.

Because the part with “Microsoft Windows Server” is always the same and you’re actually just after the rest of the string you can cut off the ugly part of the string and use the rest for a match … something like this:

$RS_W32OSCaption = (Get-WmiObject win32_operatingsystem -ComputerName $computername | Select-Object caption).Caption -match '(?<=\s)20\d{2}.+(?=$)' | Out-Null ; $Matches[0]
$KBs = ($patchesToVerify | Where-Object { $_.operating_system -match $RS_W32OSCaption } | Select-Object KB_Article).kb_article

But when I run these cmdlets, it is just pulling all KBs instead of single operating system related

$patchesToVerify Operating_System KB_Article ---------------- ---------- 2012 R2 Standard KB4530730 2016 Standard KB4530689 2008 Standard KB4530719 2012 Standard KB4530698 2008 R2 Standard KB4530692 2016 Standard KB4532936 2016 Standard KB4534293 2016 Standard KB4532933 2008 Standard KB4534312 2012 R2 Standard KB4534978 2008 Standard KB4534979 2016 Standard KB4534271 2008 R2 Standard KB4534314 2012 Standard KB4354977 2012 Standard KB4534288 2012 R2 Standard KB4534309 2008 Standard KB4534312 2008 R2 Standard KB4534876 2008 Standard KB4537822 2016 Standard KB4537759 2008 R2 Standard KB4537813 2012 R2 Standard KB4537803 2016 Standard KB4537764 2012 Standard KB4537794 2016 Standard KB4537762 PS > $patchesToVerify | ?{$.operating_system -eq $Matches[0]} | select Kb_article PS \Scripts> PS C:\Scripts> ($patchesToVerify |Where-Object {$.operating_system -eq (Get-WmiObject win32_operatingsystem -ComputerName $compu tername | Select-Object caption).Caption -match ‘(?<=\s)20\d{2}.+(?=$)’ | Out-Null ; $Matches[0]} | Select-Object KB_Article).kb_article KB4530730 KB4530689 KB4530719 KB4530698 KB4530692 KB4532936 KB4534293 KB4532933 KB4534312 KB4534978 KB4534979 KB4534271 KB4534314 KB4354977 KB4534288 KB4534309 KB4534312 KB4534876 KB4537822 KB4537759 KB4537813 KB4537803 KB4537764 KB4537794 KB4537762 PS C:\Scripts>

Sorry! i inserted as source code but it is display in this ugly format.

 

 

You have to use the “PRE” tags.

That’s strange. What’s the encoding of the csv file, utf8 no bom? Utf8 with bom works for me. Note that export-csv is ascii by default. What does it say when you open the csv in notepad and do save as?

import-csv file.csv

company
-------
microsoft©