Skip to content

Instantly share code, notes, and snippets.

@gislig
Created May 10, 2018 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gislig/20fc3a6e244f56d8dc0d3b2ab8f50f71 to your computer and use it in GitHub Desktop.
Save gislig/20fc3a6e244f56d8dc0d3b2ab8f50f71 to your computer and use it in GitHub Desktop.
Simple way to add class to Powershell
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