Closed RS30 closed 6 years ago
Hi @RS30 . These are question of a more general PowerShell nature than anything PowerNSX specific. PowerShell includes the extremely useful import-csv cmdlet that allows you to read a CSV file and output PowerShell objects to the pipeline where you can iterate over them and do what you want. It is likely a very simple import-csv
In answer to your second question, all the 'Get-*' PowerNSX cmdlets already do return PowerShell Objects (XML objects technically, but can be manipulated like any other PowerShell object), so there is no 'conversion' required. Posting objects back to NSX can usually be easily accomplished with the Invoke-NsxRestMethod cmdlet that takes XML objects as an argument. The modification of those objects between import/export (which you dont explicitly ask about, but is the important bit) is where the challenge is. Simple text properties are trivial ($obj.name = "NewName"} but creation of new properties, or appending to collections of properties (XML child nodes) is more advanced and requires a better than passing familiarity with XML and the dotNet XML classes to accomplish. I don't recommend you try this on PowerShell 101 level skill.
I also recommend you take a look at the PowerNSX book @pandom (Anthony Burke) wrote a year or so back - it has a lot of good starting points that will help you get familiar with the out of the box capability of PowerNSX.
Hi nmbradford,
Thanks for your response. running foreach from a csv is not an issue. the second part is the difficult part where I wanted to seek more guidance.
I will read the book as well and proceed. thanks.
Hi All,
I am in the process of building firewall rules for an application. is there a way to pass the input from a CSV file to build the new firewall rules ?
I want to include the below from the CSV File . Firewall Rule Name,Source,Destination,Service,Action,appliedto
can someone share how to achieve this most efficiently ? also how can we import the object from NSX and convert it in powershell usable object form to and then post it back via powershell to NSX ?
any suggestions or starting points are most welcome.