count array, create enough variables for number of array items as variables then knowingly call them

Posted on 2012-09-05
Last Modified: 2012-10-22
am trying to create a function for tables. i figured the best way would be to put my column headers in an array, count the array, set a variable as 0 to use as a counter, and while the array count is greater than the counter, set a variable called "col1" or whatever the counter is. i can then setup datatable structures for the columns.
problem is, how do i then call them??
Question by:marexit
    1 Comment
    LVL 16

    Accepted Solution

    Well, I suppose you could do it like this.

    $arrHeaders = "col1","col2","col3","col4"
    foreach ($variable in $arrHeaders)
       New-Variable -Name $variable
       Get-Variable $variable

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    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 …
    Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now