Solved

Powershell - Dynamically named DataTable

Posted on 2016-07-27
2
18 Views
Last Modified: 2016-07-27
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?
0
Comment
Question by:Dustin Saunders
2 Comments
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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

0
 
LVL 12

Author Closing Comment

by:Dustin Saunders
Comment Utility
Ah, yeah good idea that would work just fine.  Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Why would I want to create a function for tracking messages? I am glad you asked. As with most monotonous/routine tasks, human error tends to creep in after doing the same task over and over again. By creating a function, you load the function once…
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now