Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8163727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:07:42+00:00 2026-06-06T19:07:42+00:00

Is it possible to have custom datatype in powershell? I would like to have

  • 0

Is it possible to have custom datatype in powershell?

I would like to have a (structured) variable like below. Following thing is not syntactically correct.I just want to club following three variables.

Variable Databasedetails {
   string  DatabaseName
   string  TableName
   string[] columnNames 
}

If Powershell has provision to do it then i can have single variable array which can help me to write queries easily.

$Databasedetails = { "DataBaseName=DB-someX","TableName=TableX"," (ColumnNames={"Col1","col2"}" 
                    "DataBaseName=DB-someY","TableName=TableY"," (ColumnNames={"Col2","colN"}"
                  }

Foreach ($DBdetails in $DataBaseDetails)
  {
      $query= "SELECT [$DBdetails.$columnName] FROM [$DBdetails$DatabaseName].[dbo].[$DBdetails.$TableName]"
      invoke-sqlcmd -query $query -ServerInstance $srvInstance"
  }

Is there any way to create structured variable and i can create array of that and process?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:07:43+00:00Added an answer on June 6, 2026 at 7:07 pm

    You will want to look into either Add-Member or Add-Type, the later being only in Powershell 2.0.

    $details = New-Object PsObject
                 | Add-Member NoteProperty DatabaseName '' -pass 
                 | Add-Member NoteProperty TableName '' -pass
                 | Add-Member NoteProperty ColumnNames @() -pass
    

    or with Add-Type

    Add-Type 'public class DatabaseDetails { public string DatabaseName; public string TableName; public string[] ColumnNames; }' -Language CSharp
    
    $details = New-Object DatabaseDetails
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would be possible to have a custom repository not associated with an entity in
Is it possible to have a custom availability macro like the __OSX_AVAILABLE_STARTING for instance.
Is it possible to have a custom icon displayed for a QAction when it
Is it possible to have scoped macros using custom defined macros through boost wave?
Is it possible to have nested set capabilities in this somewhat custom setup? Consider
I have noticed that it is possible to define a custom class and then
Is it possible to have php not to require the begin/end tags ( <?php
Is it possible to have custom headers on Amazon S3 with arbitrary naming? For
I have a table that looks like this: id datatype name value 0 nvarchar(255)
Is it possible to have a custom background and a custom knob for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.