jdhitsolutions / PSTeachingTools

:mortar_board: A set of commands and tools for teaching PowerShell. The module should work in Windows PowerShell, PowerShell 7.x and run cross-platform.
MIT License
48 stars 22 forks source link

[Bug]: All Vegetables are RAW #12

Closed hvdm closed 1 month ago

hvdm commented 1 month ago

Describe the problem

Made a post in Pluralsight as well. All vegetables are RAW when you do a Get-Vegatable. It looks like the rawveggies.json isn't processed correctly.

Expectation

When running my FixVegatbles.ps1 in each session, it's working as it should be.

$docFolder = ([Environment]::GetFolderPath("MyDocuments")) $rawPath = Join-Path -path "$docFolder\PowerShell\Modules\PSTeachingTools\4.2.0\Code" -ChildPath rawveggies.json

$json = Get-Content -path $rawPath | ConvertFrom-Json

$StatusMap = @{ 0 = 'Raw' 1 = 'Boiled' 2 = 'Steamed' 3 = 'Sauteed' 4 = 'Fried' 5 = 'Baked' 6 = 'Roasted' 7 = 'Grilled' }

foreach ($vegetable in $json) { $name = $vegetable.Name $oldState = (Get-Vegetable -Name $vegetable.Name).CookedState [int32]$newState = $vegetable.Cookingstate [string]$newStateName = $StatusMap[$newState]

Write-Host "Convert $($name) from $($oldState) to $($newStateName)"
Set-Vegetable -Name $name -CookingState $newStateName

}

Additional Information

The above script works but needs to be run anytime again. Happens on 5.1 as on 7.4.5

PowerShell version

Other

Platform

Windows 10 Pro or Enterprise

Additional Checks

jdhitsolutions commented 1 month ago

Very odd since I haven't made any changes to this in quite awhile. But, I have duplicated the problem. Investigating.

jdhitsolutions commented 1 month ago

Even though the JSON file has a value for the cooked state, when you import the module all the vegetables are raw by design. This is so you can learn to write code like your script. Still, I should update the documentation to make this clear.

hvdm commented 1 month ago

I am busy with the Pluralsight Fundamental course (12 of them :o) and your screen examples shows up with the values from the Json file. Thats why I asumed that it was wrong.

Maybe it's better that you load those values by default, it will match the courses you made.

jdhitsolutions commented 1 month ago

Alright. You convinced me.

hvdm commented 1 month ago

Thanks

jdhitsolutions commented 1 month ago

Update to v4.3.0 of the PSTeachingTools module from the PowerShell Gallery.

hvdm commented 1 month ago

Thank you for the quick fix, works as expected