classes.txt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. class Device {
  2. [string]$Brand
  3. [string]$Model
  4. [string]$VendorSku
  5. [string]ToString(){
  6. return ("{0}|{1}|{2}" -f $this.Brand, $this.Model, $this.VendorSku)
  7. }
  8. }
  9. class Rack : Device {
  10. hidden [int] $Slots = 8
  11. static [Rack[]]$InstalledRacks = @()
  12. [int]$Slots = 8
  13. [string]$Brand
  14. [string]$Model
  15. [string]$VendorSku
  16. [string]$AssetId
  17. [Device[]]$Devices = [Device[]]::new($this.Slots)
  18. Device(
  19. [string]$b,
  20. [string]$m,
  21. [string]$vsk
  22. ){
  23. $this.Brand = $b
  24. $this.Model = $m
  25. $this.VendorSku = $vsk
  26. }
  27. [void] AddDevice([Device]$dev, [int]$slot){
  28. ## Add argument validation logic here
  29. $this.Devices[$slot] = $dev
  30. }
  31. [void]RemoveDevice([int]$slot){
  32. ## Add argument validation logic here
  33. $this.Devices[$slot] = $null
  34. }
  35. [int[]] GetAvailableSlots(){
  36. [int]$i = 0
  37. return @($this.Devices.foreach{ if($_ -eq $null){$i}; $i++})
  38. }
  39. }
  40. $rack = [Rack]::new()
  41. $surface = [Device]::new()
  42. $surface.Brand = "Microsoft"
  43. $surface.Model = "Surface Pro 4"
  44. $surface.VendorSku = "5072641000"
  45. $rack.AddDevice($surface, 2)
  46. $rack
  47. $rack.GetAvailableSlots()