Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Howto create custom objects/classes

Reply
 
Old 03-28-2008   #1 (permalink)
Carson


 
 

Howto create custom objects/classes


Hi,
when using vbscript, i created a class with several propertys and methods.
The main purpose was to create standardized scripts while reducing the coding.
I want to change to powershell scripting and want to create the similar to
my vbscript class.

Something like:
class foo
property log
property errorlog
method init
method add
method run
function finish(runlevel)
end

i thought about something like this in powershell scripting language:

$myScript = New foo (This is the predefinied Framework in powershell)
$myScript.init

run powershell scripts ...

$myScript.finish(1)

My problem is, that i did not find anything that could help me.

Kind Regards

Carson


My System SpecsSystem Spec
Old 03-28-2008   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: Howto create custom objects/classes

Carson wrote:
Quote:

> Hi,
> when using vbscript, i created a class with several propertys and methods.
> The main purpose was to create standardized scripts while reducing the coding.
> I want to change to powershell scripting and want to create the similar to
> my vbscript class.
>
> Something like:
> class foo
> property log
> property errorlog
> method init
> method add
> method run
> function finish(runlevel)
> end
>
> i thought about something like this in powershell scripting language:
>
> $myScript = New foo (This is the predefinied Framework in powershell)
> $myScript.init
I don't know how to create your own class in PowerShell, but creating a
custom object is easy...

To create proproties for an object:
http://www.bsonposh.com/modules/wordpress/?p=25

An example of methods:
http://groups.google.com/group/micro...0c2980fea1a925

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 03-28-2008   #3 (permalink)
ajax76


 
 

Re: Howto create custom objects/classes

On 28 ÍÁÒ, 19:52, Carson <Car...@xxxxxx> wrote:
Quote:

> Hi,
> when using vbscript, i created a class with several propertys and methods.
> The main purpose was to create standardized scripts while reducing the coding.
> I want to change to powershell scripting and want to create the similar to
> my vbscript class.
>
> Something like:
> class foo
> š š š šproperty log
> š š š šproperty errorlog
> š š š šmethod init
> š š š šmethod add
> š š š šmethod run
> š š š šfunction finish(runlevel)
> end
>
> i thought about something like this in powershell scripting language:
>
> $myScript = New foo (This is the predefinied Framework in powershell)
> $myScript.init
>
> run powershell scripts ...
>
> $myScript.finish(1)
>
> My problem is, that i did not find anything that could help me.
>
> Kind Regards
>
> Carson

Look here
get-help add-member -full

and here
http://www.manning.com/payette/WPA_Example_Code.zip
Open folder 'chapter08'
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
howto backup custom emoticons for Messenger Live in Vista Vista file management
Can I create a Default output format for custom objects PowerShell
PowerShell Custom Objects PowerShell
Using entlib 2 from custom objects PowerShell
Info: Can you create your own objects with custom properties. PowerShell


Vista Forums 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 Ltd

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