Powershell - Dynamically named DataTable

Dustin Saunders
Dustin Saunders used Ask the Experts™
on
Experts-

I use code similar to this to dynamically create variables:
New-Variable -Name "var$i" -Value $x
Get-Variable -Name "var$i" -ValueOnly

Open in new window


But I am not sure how to proceed creating dynamically named DataTables.

For example, I have a CSV with sets of domains on them.  For each domain, I want to create a dynamically named DataTable to store the data for that specific domain.  After doing a bit of processing I'll need to merge all the data tables into one procedurally.  Is there a way I can dynamically create these tables?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Instead of using dynamically named variables, why not use a hashtable?
$Domains = @{}
$SomeDomain = 'abc.com'
$Domains[$SomeDomain] = New-Object -TypeName System.Data.Datatable

Open in new window

Dustin SaundersCo-Founder and Chief Architect
Top Expert 2016

Author

Commented:
Ah, yeah good idea that would work just fine.  Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial