# Problems migrating from 5.1 to 7.4.1

**URL:** <https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743>\
**Category:** PowerShell Help\
**Created:** [March 9, 2024, 8:01pm UTC](https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743 "2024-03-09T20:01:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henning\_Reckey](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Henning\_Reckey](https://forums.powershell.org/u/Henning_Reckey)\
**Post date:** [March 9, 2024, 8:01pm UTC](https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743/1 "2024-03-09T20:01:32Z")

</div>

A couple of weeks ago, I was low on ideas for new snippets and scripts. I then decided to look ahead and prepare for a new era.  
The preparations went smooth and it looked like a walkover; but so far it hasn’t been.  
I have collaborated with AI on many tricky things in Powershell, but here at last “he” was running out of suggestions and adviced me to a Forum like this one. So here I am.  
The last thing I made my friend AI do, was making a 10 point plan for testing out my Win10 installation running Powershell ISE and it went fine. I also made “him” make a function that ran through my approx. 200 snippets and scripts, that tested for 7.4.1 acceptance, only 2 passed, that’s when he adviced me to join you.  
I have collected all my things so they are menu driven, with System.Windows.Forms.ListBox as driver. Now hold on tight:  
Below is my listbox and it works fine in 5.1; but doesn’t show in 7.4.1. I know you will all say, we can’t reproduce that; but if I’m the only one, how can I then get it fixed?

```auto
#load the appropriate assemblies
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")

#create chart
$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart 
$Chart.Width = 500
$Chart.Height = 400
$Chart.Left = 40
$Chart.Top = 30

#create a chartarea to draw on and add to chart
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea. 
$Chart.ChartAreas.Add($ChartArea)

#listbox form
$form = New-Object System.Windows.Forms.Form
$form.Text = 'HeatingChart 2020'
$form.Size = New-Object System.Drawing.Size(300,280)
$form.StartPosition = 'CenterScreen'

#legend
$legend = New-Object system.Windows.Forms.DataVisualization.Charting.Legend
$legend.name = "Legend1"
$Chart.Legends.Add($Legend)
$Legend.Docking = 'bottom'

$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,190)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)

$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150,190)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = ' Choose a 3 year period'
$form.Controls.Add($label)

#listbox
$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Location = New-Object System.Drawing.Point(10,40)
$listBox.Size = New-Object System.Drawing.Size(260,20)
$listBox.Height = 135         

#[void]$listBox.Items.AddRange($Xyear)
$form.Controls.Add($listBox)
$form.Topmost = $true
$result = $form.ShowDialog()

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [March 9, 2024, 9:03pm UTC](https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743/2 "2024-03-09T21:03:05Z")

</div>

Hey Henning!

Welcome! When you have a moment, please go back and format your code: Formatting your code: [How to format code on PowerShell.org](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif)

Sometimes, funky things can happen if all the code isn’t formatted as code. for example the code you provided starts and ends with ‘’’. I don’t t hink that’s intended. Much appreciated!

The code for me throws errors but does pop up a GUI at the end in both 5 and 7. You’ll need to verify and step through those lines of code and fix them. For example, I don’t think this line is right:

```powershell
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea.

```

i don’t think there should be an ending period.

Next we don’t know what you’re expecting. You spent a ton of time talking about AI and telling a story instead of telling us exactly what the issue is. What is the issue, what is the expected result, and what errors are you hitting? You need to help us help you.

This outputs the same thing for me in both 5 and 7:

```powershell
#load the appropriate assemblies
[void][Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
[void][Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms.DataVisualization')

#create chart
$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart
$Chart.Width = 500
$Chart.Height = 400
$Chart.Left = 40
$Chart.Top = 30

#create a chartarea to draw on and add to chart
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
$Chart.ChartAreas.Add($ChartArea)

#listbox form
$form = New-Object System.Windows.Forms.Form
$form.Text = 'HeatingChart 2020'
$form.Size = New-Object System.Drawing.Size(300,280)
$form.StartPosition = 'CenterScreen'

#legend
$legend = New-Object system.Windows.Forms.DataVisualization.Charting.Legend
$legend.name = 'Legend1'
$Chart.Legends.Add($Legend)
$Legend.Docking = 'bottom'

$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,190)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)

$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150,190)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = 'Choose a 3 year period'
$form.Controls.Add($label)

#listbox
$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Location = New-Object System.Drawing.Point(10,40)
$listBox.Size = New-Object System.Drawing.Size(260,20)
$listBox.Height = 135

#[void]$listBox.Items.AddRange($Xyear)
$form.Controls.Add($listBox)
$form.Topmost = $true
$result = $form.ShowDialog()

```

I fixed that period issue and all the single/double quote issues, which may have been from copy/pastinng into the forum. This makes VS code happy, with the exception of course, $result isn’t used but I trhink that’s ok. AI is great, but I’d suggest learning what it’s doing so you can better fix issues. AI, in my experience, doesn’t always do the job correctly, and can make up things out of thin air with 100% confidence. Learning what things are doing and simply stepping through your code a line at a time and see what’s failing and what isn’t is a great way to start learning PS.

---

<div class="post-metadata">

**Author:** ![Henning\_Reckey](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Henning\_Reckey](https://forums.powershell.org/u/Henning_Reckey)\
**Post date:** [March 10, 2024, 1:48pm UTC](https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743/3 "2024-03-10T13:48:56Z")

</div>

Hi there Nick and thank you.  
What is my story telling all about. I tried to give my Powershell background. I tried to tell, that now is the time  
to shift from 5.1 to 7.4.1. I tried to tell that it gives errors and that is why I’m here now.  
I tried to tell that a big part of success is that the underlying system is a 100% in place. I tried to tell that I can’t know  
if it is; but I have tried to get AI to help test it, so that’s not the main problem for errors.

Now, what do I expect of all this. I hope to start a heading saying: Problems with migrating from 5.1 to 7.4.1  
and tell about all the things I was met with, either in one Heading or in as many as it takes.

Finally, I thought I had seen, that you wanted code to be surrounded by 3 ticks and the period you said you have changed,  
is not in my the original draft. I have added a major thing to the story and that is, I’m running Powershell ISE

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 10, 2024, 2:18pm UTC](https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743/4 "2024-03-10T14:18:48Z")

</div>

> [@Henning\_Reckey](#):
>
> that now is the time  
> to shift from 5.1 to 7.4.1.

Why is that? Windows PowerShell will not go away any time soon? If there is no particular function you need from 7.x you don’t have to migrate. 🤷🏼‍♂️

> [@Henning\_Reckey](#):
>
> I’m running Powershell ISE

I’d recommend using VSCode instead.

> **[Visual Studio Code - Code Editing. Redefined](https://code.visualstudio.com/)**
>
> Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications.  Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [March 10, 2024, 2:35pm UTC](https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743/5 "2024-03-10T14:35:17Z")

</div>

Hey Henning,

Thank you for updating the original code. It is very much appreciated!

I think there might be some misunderstanding, I apologize. The questions I asked are really geared towards your specific issue and not from a general 5 → 7 migration. From a general perspective, when you create an issue on the forums, we really just need to focus on that specific issue to resolve. we need to focus on the specific task you are asking us about. Given that, each _specific_ issue you write about on these forums, generally includes a few things that will help us help you (some of which you’ve done, thank you!):

1. Problem Statement (what problem are you trying to overcome?)
2. Desired Result (What is the output suppose to look like?)
3. Share your formatted code
4. Share any thing you have tried, as well as the error messages you are running into.

The more details the better, and in most cases, it’s best to assume we know nothing about your environment, how your running the code, etc. To that end:

In my previous response, I took a quick stab at a small refactor of your code. It fixes one small bug I found. However, that bug wasn’t preventing the GUI from working. The code I provided displays the following GUI and runs without errors in both 7 and 5.1:  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/f/f13a584cf7c006197fb47cf37e33b836b69e235b.png)

Is this the expected output? It seems incomplete, like i’m missing data in the main area but that’s the code you provided, and it performs, on my end, identically in both powershell 5 and 7, so from my perspective, there’s not a 5 vs 7 issue here. However, if you’ve modified the code for 7 because of AI, and hte original PS5 code works differently, you need to clarify this and share your original PS5 code. I’m just not sure how to help if I don’t know what the expected result is.

---

<div class="post-metadata">

**Author:** ![Henning\_Reckey](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Henning\_Reckey](https://forums.powershell.org/u/Henning_Reckey)\
**Post date:** [March 10, 2024, 6:42pm UTC](https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743/6 "2024-03-10T18:42:16Z")

</div>

> [@Henning\_Reckey](#):
>
> A couple of weeks ago, I was low on ideas for new snippets and scripts. I then decided to look ahead and prepare for a new era.

Hi Olaf thank you for your post. The lines above made me take the decision. But you are right there is absolutely nothing to complain about (everything works in 5.1), except I am looking for new adventures 🙂 As for ISE vs. VsCode, I can say I run both but take ISE as first choise

---

<div class="post-metadata">

**Author:** ![Henning\_Reckey](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Henning\_Reckey](https://forums.powershell.org/u/Henning_Reckey)\
**Post date:** [March 10, 2024, 6:56pm UTC](https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743/7 "2024-03-10T18:56:46Z")

</div>

This is how it invites to a graph for a 3 year period, when chosen the graph shows; but not in 7.4.1

```auto
#load the appropriate assemblies
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")

#create chart
$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart 
$Chart.Width = 500
$Chart.Height = 400
$Chart.Left = 40
$Chart.Top = 30

#create a chartarea to draw on and add to chart
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
$Chart.ChartAreas.Add($ChartArea)

#listbox form
$form = New-Object System.Windows.Forms.Form
$form.Text = 'HeatingChart 2020'
$form.Size = New-Object System.Drawing.Size(300,280)
$form.StartPosition = 'CenterScreen'

#legend
$legend = New-Object system.Windows.Forms.DataVisualization.Charting.Legend
$legend.name = "Legend1"
$Chart.Legends.Add($Legend)
$Legend.Docking = 'bottom'

$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,190)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)

$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150,190)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = ' Choose 3 year period'
$form.Controls.Add($label)

#listbox
$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Location = New-Object System.Drawing.Point(10,40)
$listBox.Size = New-Object System.Drawing.Size(260,20)
$listBox.Height = 135

                 #set years in listbox
                 [void] $listBox.Items.Add(' 👀')
                 $y=2020
                 $x=2021
                 $z=2022
                 $count = 1
                 $Xyear = @()
                 $antyear = (Get-Date).year - 2019
                 While ($count -lt $antyear)
                 {
                      $Xyear += @("$y $x $z")
                      $y++
                      $x++
                      $z++
                      $count ++
                 }

                 [void]$listBox.Items.AddRange($Xyear)
                 $form.Controls.Add($listBox)
                 $form.Topmost = $true
                 $result = $form.ShowDialog()

```

---

<div class="post-metadata">

**Author:** ![Henning\_Reckey](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Henning\_Reckey](https://forums.powershell.org/u/Henning_Reckey)\
**Post date:** [March 10, 2024, 9:27pm UTC](https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743/8 "2024-03-10T21:27:34Z")

</div>

I have been testing and have made this observation:

Version 5.1

seen in command pane:

C:\Users\Henning\OneDrive\Personlige\WindowsPowerShell\LookUpCmd.ps1

Result: Listbox

It works like using Run script button PF5

* * *

Change to 7.4.1

seen in command pane:

Add-Type -AssemblyName System.Windows.Forms  
Add-Type -AssemblyName System.Drawing  
$SendKeys = [System.Windows.Forms.SendKeys]

$form = New-Object System.Windows.Forms.Form  
$form.Text = ‘Commandshell’  
#$form.Size = New-Object System.Drawing.Size(300,280)  
$form.Size = New-Object System.Drawing.Size(300,480)  
$form.StartPosition = ‘CenterScreen’

$okButton = New-Object System.Windows.Forms.Button  
$okButton.Location = New-Object System.Drawing.Point(75,404)  
$okButton.Size = New-Object System.Drawing.Size(75,23)  
$okButton.Text = ‘OK’  
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK  
$form.AcceptButton = $okButton  
$form.Controls.Add($okButton)

#$cancelButton = New-Object System.Windows.Forms.Button  
#$cancelButton.Location = New-Object System.Drawing.Point(150,404)  
#$cancelButton.Size = New-Object System.Drawing.Size(75,23)  
#$cancelButton.Text = ‘Cancel’  
#$cancelButton.Text = ‘Sort’  
#$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel  
#$form.CancelButton = $cancelButton  
#$form.Controls.Add($cancelButton)

$label = New-Object System.Windows.Forms.Label  
$label.Location = New-Object System.Drawing.Point(10,20)  
$label.Size = New-Object System.Drawing.Size(280,20)  
$label.Text = ’ ’  
$form.Controls.Add($label)

$listBox = New-Object System.Windows.Forms.ListBox  
$listBox.Location = New-Object System.Drawing.Point(10,40)  
$listBox.Size = New-Object System.Drawing.Size(260,20)  
#$listBox.Height = 135  
$listBox.Height = 360

################################################### Uden sort #################################################

# (SS64 = 1) og (PDQ = 2)

$A = @(  
‘add-appxpackage’

And so on, the rest of the script; but no indication of exec. It works like using Run selection button PF8

* * *

Question: why the difference from version 5.1 and to 7.4.1 (this is probably what makes the error)

---

<div class="post-metadata">

**Author:** ![Henning\_Reckey](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Henning\_Reckey](https://forums.powershell.org/u/Henning_Reckey)\
**Post date:** [March 12, 2024, 2:07pm UTC](https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743/9 "2024-03-12T14:07:38Z")

</div>

A break through. I have tested in VSCode version 7.4.1 and the listbox is showing. But we still need to see it work in Powershell ISE

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 12, 2024, 8:28pm UTC](https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743/10 "2024-03-12T20:28:03Z")

</div>

> [@Henning\_Reckey](#):
>
> 7.4.1 … But we still need to see it work in Powershell ISE

PowerShell\_ISE does not support PowerShell core (6.x and up). ☝🏼

---

<div class="post-metadata">

**Author:** ![Henning\_Reckey](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Henning\_Reckey](https://forums.powershell.org/u/Henning_Reckey)\
**Post date:** [March 12, 2024, 8:58pm UTC](https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743/11 "2024-03-12T20:58:47Z")

</div>

Hi Olaf. In that case, case is closed, and you are right, there is no need to change if no severe need. Thank you for the information !

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [April 11, 2024, 8:59pm UTC](https://forums.powershell.org/t/problems-migrating-from-5-1-to-7-4-1/23743/12 "2024-04-11T20:59:37Z")

</div>

Closed on April 11, 2024, 8:59pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
