Created
May 10, 2018 09:06
-
-
Save gislig/20fc3a6e244f56d8dc0d3b2ab8f50f71 to your computer and use it in GitHub Desktop.
Simple way to add class to Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class Fruit { | |
#Set the variable | |
[string]$FruitName | |
#Create the constructor | |
Fruit ($FruitName) { | |
$this.FruitName = $FruitName | |
} | |
} | |
#Initialize the class | |
[Fruit]$NewFruit | |
#Get the fruit data, might be a sql data | |
$Fruits = "Banana", "Apple", "Orange" | |
#Write the fruit data to the class | |
$Fruits | % { $NewFruit.FruitName = $_ } | |
#Writing the fruits to console or do something | |
$Fruits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment