Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell - Dynamically named DataTable

Posted on 2016-07-27
2
Medium Priority
?
43 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 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 41731387
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 14

Author Closing Comment

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦
Screencast - Getting to Know the Pipeline

926 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