Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Array or Database or ??

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 08-02-2007   #1 (permalink)
Tonino Bruno
Guest


 

Array or Database or ??

Dear,

I am confused about the different posibilities of storing information in
powershell. I am not a programmer more of a consultant doing some sysadmin
tasks from time to time in projects.

right now I have created a script that will display a form with a dropdown
box where i can select a certain "profile" let's say. My idea is that once
the confirmation is hit I get the index number out of the listbox and
retrieve my information from a pre-built datalist.

However how should I construct such a data list containing multiple rows and
multiple columns ?

The results I am after is what you get after doing an import-csv. Basically
you get an object which is indexed and has multiple properties.

I've looked at creating my own custom object with multiple properties but I
have no clue how to add data to it?

I've been going at it for too long now and it's pretty late here in belgium
so my mail might not make a lot of sense :-)

Sincerely,
Tonino Bruno
Belgium



My System SpecsSystem Spec
Old 08-02-2007   #2 (permalink)
Marco Shaw
Guest


 

Re: Array or Database or ??


> I've looked at creating my own custom object with multiple properties but I
> have no clue how to add data to it?


I have an example here of creating your own object:
http://marcoshaw.blogspot.com/2007/0...s-example.html

I was mostly inspired by this post:
http://thepowershellguy.com/blogs/po...baby-name.aspx

Marco
My System SpecsSystem Spec
Old 08-05-2007   #3 (permalink)
Bruce Payette [MSFT]
Guest


 

Re: Array or Database or ??

I was doing something similar myself recently so I wrote a handy function
for converting a collection of hashtables into objects:

function Convert-HashToObject
{
$($args; $input) | foreach {
$map = $_.psbase.keys |
foreach {
@{
name="$_"
expression=$executioncontext.InvokeCommand.NewScriptBlock(
"`$_.$_")
}
}

$_ | select $map
}
}

This funciton takes advantage of Select-Object's ability to create new
psobjects from descriptions. Here's an example of how to use the function.
First a collection of hash tables:

PS (3) > @{a=1;b=2;c=3},@{a=11;b=22;c=33}

Name Value
---- -----
a 1
b 2
c 3
a 11
b 22
c 33

and now convert that collection to PSObjects:

PS (4) > @{a=1;b=2;c=3},@{a=11;b=22;c=33} | Convert-HashToObject

a b
c
- -
-
1 2
3
11 22
33


-bruce

--
Bruce Payette [MSFT]
Windows PowerShell Technical Lead
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

Visit the Windows PowerShell Team blog at:
http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:
http://www.microsoft.com/technet/scr.../hubs/msh.mspx
My Book: http://manning.com/powershell

"Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:%23NaABaW1HHA.1344@TK2MSFTNGP04.phx.gbl...
>
>> I've looked at creating my own custom object with multiple properties but
>> I have no clue how to add data to it?

>
> I have an example here of creating your own object:
> http://marcoshaw.blogspot.com/2007/0...s-example.html
>
> I was mostly inspired by this post:
> http://thepowershellguy.com/blogs/po...baby-name.aspx
>
> Marco



My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Works database 2007 and Office database 2003 maur scho .NET General 0 06-03-2008 01:48 AM
Compacting the database Don Live Mail 17 03-10-2008 04:51 PM
database corruption btblue Live Mail 7 03-09-2008 01:30 PM
how to assign values to array and how to create array via variable Frank PowerShell 1 03-13-2007 05:18 PM
Jet database and Vista jeffc Vista General 3 12-21-2006 09:51 AM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51