Forum Discussion

dmarquesgn's avatar
dmarquesgn
Iron Contributor
Sep 05, 2022

Powershell parse csv file to store some values to variable

Hi,

I'm working with PSWindowsUpdate module to automate some tasks related to Windows Servers Updates.

I've already created some scripting to go to each server, check which updates are available and write down the results to a centralized csv file.

As a next step I need to parse the csv to check some conditions and return the KB IDs I want to install to a variable, together with the server hostname in order to build the update command for the deployment of the updates.

So my csv has the following columns I need to parse, which are "ComputerName" and "KB". What I want to do is run through each row of the CSV, check the "KB" column and if "KB" is not empty than store the ComputerName and KB values to variables containing the KBs for each different ComputerName.

As I'm new to Powershell I can go up to parse the CSV and find the KB that is not empty, but now I'm not understanding how can I store this values to variables.
Can anyone give me some guidance?
Thanks

  • dmarquesgn's avatar
    dmarquesgn
    Iron Contributor
    One more thing. In the end my goal is to prepare a command like:
    Get-WindowsUpdate -ComputerName $server -MicrosoftUpdate -NotCategory "Drivers" -Verbose -Download -AcceptAll -ScheduleReboot "Date" -KBArticleID $KBS (This is the KBs extracted from the CSV for each server)
    • dmarquesgn's avatar
      dmarquesgn
      Iron Contributor
      Hi,
      Thanks for the note. I got the idea. Also, I was overcomplicating, I guess I'm near the end goal.

Resources