SOLVED

Powershell parse csv file to store some values to variable

Iron Contributor

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

3 Replies
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)
best response confirmed by dmarquesgn (Iron Contributor)
Solution
If I understood your request correctly you already have the necessary code for the actual execution, what you need to know is how to put values in a variable, correct?
Do you require a string, array or hashtable variable?
See here for examples on the use of each: https://docs.microsoft.com/en-us/powershell/scripting/lang-spec/chapter-05?view=powershell-7.2
Hi,
Thanks for the note. I got the idea. Also, I was overcomplicating, I guess I'm near the end goal.
1 best response

Accepted Solutions
best response confirmed by dmarquesgn (Iron Contributor)
Solution
If I understood your request correctly you already have the necessary code for the actual execution, what you need to know is how to put values in a variable, correct?
Do you require a string, array or hashtable variable?
See here for examples on the use of each: https://docs.microsoft.com/en-us/powershell/scripting/lang-spec/chapter-05?view=powershell-7.2

View solution in original post